Deployments work by uploading an archive containing your function's source code to a Google Cloud Storage bucket. Once the source code has been uploaded, Cloud Build automatically builds your code into a container image and pushes that image to Container Registry. Cloud Functions uses that image to create the container that executes your function.
You can deploy Cloud Functions from your local machine, from your GitHub or Bitbucket source repository (via Cloud Source Repositories), or from the Cloud Functions API directly.
- Deploying from Your Local Machine
- Deploying from Source Control
- Deploying from Cloud Console
- Deploying from the Cloud Functions API
When deploying, Cloud Functions looks for particular files, depending on your runtime. See Writing Cloud Functions for details. Before your function's deployment is finalized, Cloud Functions will send your function a test request to confirm that it deployed successfully.
Migrating between deployments
A function's first deployment may take several minutes to complete while the underlying infrastructure is provisioned. Redeploying an existing function is faster, and incoming traffic will be automatically migrated to your function's newest version.
As you learn about the different ways to deploy functions, it is helpful to understand some basic terminology. When you deploy a function, it is displayed in the Cloud Console, as shown below. In particular, note the Name and Executed Function fields:
- The Name field is the registered name you assign to your function.
- The Executed Function field is the name of the actual function in your source code that is executed when the deployed function gets called.
These two fields can have the same name, or the names can be different. Notice
below that the first two functions have registered names that are different from
the executed function names. The last function uses the same name for both
Building and Testing Locally
Cloud Functions execute in runtime environments based on open source languages and frameworks so you can build and test your functions locally using standard runtimes and development tools.
You can also use the Functions Framework to run and debug your functions locally for supported runtimes to make testing and debugging easier.
- Calling HTTP Functions.
- Calling Cloud Storage Trigger Functions.
- Calling Cloud Pub/Sub Trigger Functions.
- HTTP Cloud Functions Tutorial.
- Cloud Functions with Cloud Storage Tutorial.
- Cloud Functions with Cloud Pub/Sub Tutorial.