Skip to content

Create a function

View as Markdown

Create a function and get its own public HTTPS URL. You choose the hardware, a runtime, a name, and how much memory and time the function can use, then write the code. For help choosing the hardware and runtime, see Runtimes and hardware.

You need Functions activated. See Activate Functions.

  1. In MyAccount, open Compute > Functions.
  2. Click Create Function.

Create Function offers two choices, both on CPU hardware:

  • CPU Functions for code from a runtime template, such as an API, a webhook, or a data job.
  • Custom Container Image to deploy your own Docker image instead.

Select CPU Functions unless you are bringing your own image. The hardware, runtime, and name stay as you set them on this form. To change them later, create a new function.

Pick a runtime template from the list. The runtimes available depend on the hardware you chose. CPU Functions offers Python, Node.js, Go, C#, and PHP runtimes. Custom Container Image offers one runtime, also named Custom Container Image. To set it up, see Deploy a custom container image. For the full list, see Runtimes and hardware.

Enter a name in Function Name. A name uses lowercase letters, digits, and hyphens, up to 40 characters. It must start with a letter and end with a letter or digit.

Each function in your account needs its own name, whatever its status, until you delete it. A taken name gets “Function with name {name} already exists”, with your name in place of {name}. Choose a different name. A Failed function keeps its name until you delete it. To reuse that name, delete the failed function first. See Function with name {name} already exists.

The editor opens with your runtime’s code file and requirements file, one per tab. Keep the file names as they are. For the files each runtime uses, see Runtimes and hardware. Edit the code and the requirements file to fit what you want to run.

To start from the sample code, leave the code as it is. You can replace it later in the editor. See Edit a function.

Instead of typing code, you can upload a ZIP of your code in the upload area above the editor. See Upload code as a ZIP.

In Function Configuration, add Environment variables, each with a Key and a Value. See Use environment variables for the naming rules and how your code reads them.

Under System Configuration, choose:

  • Memory: 128, 256, 512, or 1024 MB. The form defaults to 128 MB. Each memory choice comes with a share of a CPU. See Runtimes and hardware for the amounts.
  • Timeout (sec): the seconds a function can run before it is stopped, from 1 to 600. The form defaults to 15 seconds.
  • (Optional) Enable Dedicated Replica: for a CPU or container function, keep 1 to 5 instances always running to avoid cold starts. Set the count in Minimum Replica. See Keep a function ready with dedicated replicas.

Start with the defaults, and raise them if the function runs out of memory or time.

Click Create. The function builds and deploys, moving through Creating and Deploying, then Running or Failed. A new Python 3.11 (Http) function with the sample code and 128 MB reaches Running in about 30 seconds.

When the function reads Running, it is ready. Its public HTTPS URL is shown on the function’s page and in the Info tab. Call it next. See Call a function.

If the function reads Failed, see Troubleshooting Functions.