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.
Before you begin
Section titled “Before you begin”You need Functions activated. See Activate Functions.
Open Create Function
Section titled “Open Create Function”- In MyAccount, open Compute > Functions.
- Click Create Function.
Choose hardware
Section titled “Choose hardware”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.
Choose a runtime
Section titled “Choose a runtime”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.
Name the function
Section titled “Name the function”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.
Write the code
Section titled “Write the code”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.
(Optional) Add environment variables
Section titled “(Optional) Add environment variables”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.
Set the system configuration
Section titled “Set the system configuration”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.
Create the function
Section titled “Create the function”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.