How to Set Up Functions on DigitalOcean App Platform

intermediate 8 min read Updated 2026-05-11
Quick Answer

Add Functions as serverless components to an existing DigitalOcean App Platform app via Control Panel by selecting source code, configuring name/routes/envs, and deploying; structure code in packages dir for auto-detection. Use CLI/API for automation. Test via app URL with curl; troubleshoot builds by verifying source dir and specs.

Prerequisites

  • DigitalOcean account with billing enabled
  • Existing App Platform app or Git repository/container image
  • Functions code structured in packages directory (e.g., Node.js handlers)
  • Repo read permissions for DigitalOcean
  • Optional: doctl CLI or API token

Step-by-Step Instructions

1

Create or Select Existing App

Ensure you have an existing app in DigitalOcean App Platform or create one via the Apps page: click Create App, select Git repository or container image source, configure resources, and deploy. Functions are serverless components auto-detected from packages directory (e.g., packages/functions-name/index.js exporting module.exports = (event, context) => {...}).
2

Navigate to App Overview

Go to the Apps page in the DigitalOcean Control Panel and select your app to open its Overview page.
3

Add Function Component

Click Add components (or Add resources). Choose Create resources from source code to add a Function, prompting the Add resources screen.
Use CLI (<code>doctl apps update</code>) or API (PUT <code>/v2/apps/{id}</code>) for automation with app spec.
4

Select Deployment Source

Choose Git repository (grant read permissions) or container image from Repository dropdown. For Git: select Branch (default: main; enable auto-redeploy), set Source directory for monorepos (e.g., /functions). Default: root (/).
App Platform auto-detects buildpacks (e.g., Node.js for <code>packages/</code>).
5

Configure Function Settings

Enter unique Name (e.g., api-functions). Confirm Branch and auto-redeploy. Set optional HTTP request routes (e.g., /api/*; defaults to root). Choose Instance size (default: 0.25 vCPU, 512 MiB RAM); edit for autoscaling (min:1, max:4; CPU:70%). Add Environment variables via Envs (e.g., API_KEY as SECRET, RUN_AND_BUILD_TIME).
Routes determine URL: <code>app_url/component_route/package/function</code>.
6

Review and Deploy

Check Summary for config, pricing (e.g., $0.0000185/GB-s + instances), alerts (DEPLOYMENT_FAILED, DOMAIN_FAILED). Click Add resources to deploy automatically; monitor on Overview or Activity tab.
7

Verify Deployment

View live URL on Overview (e.g., https://your-app.ondigitalocean.app/api/endpoint). Test with curl:
curl -X POST https://your-app.ondigitalocean.app/api/login \
-H "Content-Type: application/json" \
-d '{"username":"test","password":"test"}'
Expect 200 OK JSON response.
Defaults to JSON content-type.
8

Edit Post-Deployment Settings

Go to app Settings tab, select Function, click Edit for routes, envs, or run command (e.g., node index.js).
9

Structure Code for Detection

Organize in packages/ dir: each subdir is a package with handler files (e.g., packages/api/index.js). Include package.json for dependencies. Supports Node.js, Python, etc.
See sample repos like digitalocean/sample-functions-nodejs-qrcode.

Common Issues & Troubleshooting

Build/Deployment Failure ("DEPLOYMENT_FAILED" or "Build failed" logs)

Verify source directory (e.g., set source_dir: /functions for monorepos) and Functions structure in packages/; check build logs.

Functions not detected

Ensure code exports handlers correctly (e.g., module.exports = async (event) => {...}) in packages/ dir with package.json.

Port binding or runtime errors

Bind to 0.0.0.0 if custom; verify env vars and specs.

No auto-redeploy on Git push

Enable in branch settings; confirm repo permissions granted to DigitalOcean.

Incorrect URL/routing

Set HTTP routes (e.g., /api/*); URL follows app_url/component_route/package/function.

Prices mentioned in this guide are pulled from current plan data and may change. Always verify on the official DigitalOcean App Platform website before purchasing.