How to Manage Functions in App Platform

App Platform is a Platform-as-a-Service (PaaS) offering that allows developers to publish code directly to DigitalOcean servers without worrying about the underlying infrastructure.

Functions are blocks of code that run on demand without the need to manage any infrastructure. You can develop on your local machine, test your code from the command line using doctl, then deploy to App Platform — no servers required.

Create Functions

  1. In the Apps section of the DigitalOcean Control Panel, select your app, then click the Create dropdown and choose Create Resources From Source Code to add a Function.
Resources screen
  1. Select the repository service to retrieve your source code from, either: GitHub, GitLab, DigitalOcean Container Registry, Docker Hub, or a sample app. If you are connecting to your repository from DigitalOcean for the first time, you will need to click the Manage Access button to provide DigitalOcean access to the repositories or containers, then refresh this page.

  2. Select the repository from the Repository drop-down list. Next, select which branch of the source repo you’d like to use as the source. Optionally, for monorepos, specify the folder that contains the source in the Source Directory field. For containers, specify the image tag to use. Click Next.

    App Platform will inspect the code, select an appropriate resource type and also detect any appropriate build and run commands.

Create function

You cannot change a Function to another resource type. To change the Function specifications, click the edit icon to open the Settings page of the Function. Here, you can edit the name, and the request route. Click Expand in the Functions section to see the packages and functions to be deployed. Click Save to confirm your changes.

Create function settings
  1. Optionally, if you want to specify additional resources, click the Add Additional Resource From Source link, repeat the procedure and click Next.

  2. If you need to use environment variables, click Edit to the right of the resource name and supply them. Click the Encrypt checkbox to ensure a variable’s value is obscured in all build, deploy, and application logs.

    To specify an app-level environment variable, click Edit to the right of Global. Click Save and then click Next.

    Resources env variables
  3. Review the resources, environment variables and pricing, and click Create Resources.

Edit Functions

In the Apps section of the DigitalOcean Control Panel, select your app and click on the Settings tab. Click the Function you’d like to edit.

You can use the configuration settings you see here to change the Function’s scaling behavior, modify environment variables, edit commands, and more.

Get Function URLs

To find the live URL of each function in your Function component, click to the Settings tab of your app and click the Function component you’d like to inspect.

Function settings

The Functions table displays information about all of the functions deployed in the component. The Name of each function is a clickable link that opens the function’s URL in a new window in your browser.

Opening the live URL of a function directly in your browser can result in errors if your function is expecting input parameters. Use API testing tools like Postman, curl, or your programming language’s HTTP client library to test the URL with properly formatted HTTP requests.

You can also click the Copy button next to the function name to copy the live URL to your clipboard.

Enable Trusted Sources

Functions in App Platform supports trusted sources with DigitalOcean Managed Databases. You can add your app as a trusted source on managed database clusters to enable secure connection from the app to the database.

When you add an app as a trusted source for a database, all components of the app, including any functions components, have secure access to the database cluster.

To configure the functions component to connect to the database cluster, set environment variables from the managed database configuration:

  • DATABASE_URL for the connection URL.
  • DATABASE_PASSWORD for the password.
  • DATABASE_USER for the username to use to connect.
  • DATABASE_NAME for the name of the database cluster.

When using functions to connect to databases, we recommend reusing the database connection across multiple function invocations or closing the connection with every invocation to avoid hitting the database’s connection limit. The function environment is reused across function invocations, so you can initialize the connection in a persistent global variable.

We do not currently support trusted sources with MongoDB or Postgres connection pools.

Log Forwarding

Functions components on App Platform can forward console and error logs to a third-party logging service. We currently support Logtail and Datadog:

  • For Datadog, the configuration requires an Endpoint and an API Key.
  • For Logtail, create an HTTP source and use the resulting Token for the configuration.
We currently do not support Papertrail as a log forwarding provider for function components in App Platform.

Enabling log forwarding requires two steps:

  • First, configure a log forwarding destination, using either the control panel interface or by updating your app’s app spec file.
  • Then, update your function’s project.yml file to properly handle the LOG_DESTINATIONS environment variable.

Configure the Log Forwarding Destination

You can configure log forwarding for function components using the control panel interface or by updating your app’s app spec file.

To configure a function component’s log forwarding through the control panel, you need to navigate to the component’s Settings page. Start at the Apps page, then click on the App you’d like to update. Select Settings and click on the function component.

Click the Edit button in the Log Forwarding section, then press the Add Destination button. This opens the Add Log Destination dialog:

Screenshot of the Add Log Destination dialog with fields for a name, log destination type, token, and buttons for canceling and adding the log destination

Fill out a Name, select your Log Destination Type, and then fill in the details needed for your destination type. Press Add Log Destination to complete the process.

Adding a log forwarding destination to your function component also adds an environment variable to your component with the key of LOG_DESTINATIONS. You can view this new environment variable in the Environment Variables section of your function component’s settings page. If you remove this environment variable, log forwarding for your function stops working.

You can add log forwarding destinations to function components by updating the App’s app spec file. See the log_destinations section of the App Spec reference for details. Here is an example Logtail destination:

- name: <example-destination>
    token: <your-token>

Place the log forwarding destination in the portion of your app spec that configures the function component you’re enabling log forwarding for.

Additionally, in the same component section, add the following environment variable:


The value of ${_self.FUNCTIONS_LOG_DESTINATION_JSON} is provided by App Platform. It is a JSON structure with configuration details for log forwarding destinations.  

Update Your project.yml File

To complete the setup, add the LOG_DESTINATIONS environment variable to your function’s project.yml file:


This passes the component-level LOG_DESTINATIONS environment variable into to the actual Function process. After you update project.yml, redeploy your function component.

Destroy Functions

In the Apps section of the DigitalOcean Control Panel, select your app and click on the Settings tab. Click on the Function you’d like to destroy.

You can destroy the Function by clicking the Destroy Component button on the bottom of the page and entering its name to confirm your selection.

Function Limits

All Functions product limits also apply to function components in App Platform. See the following link for details.

Limits and known issues for DigitalOcean Functions.