Skip to main content

Search the Dev Center

Search tutorials, templates, examples, and more.

Google Cloud Functions in Python, Go, and TypeScript deployed with TypeScript

Basic example of a serverless GCP functions in TypeScript, Python and Go

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set gcp-ts-serverless-raw
cd pulumi-examples/gcp-ts-serverless-raw

This example deploys three Google Cloud Functions. “Hello World” functions are implemented in Python, Go, and TypeScript. The Pulumi program is implemented in TypeScript.

Prerequisites#

  1. Install Pulumi
  2. Configure GCP credentials
  3. Install Node.js

Deploying the example#

  1. Create a new stack:

    Terminal window
    pulumi stack init testing
  2. Configure your GCP project and region:

    Terminal window
    pulumi config set gcp:project <your-gcp-project>
    pulumi config set gcp:region <gcp-region>
  3. Install dependencies:

    Terminal window
    npm install
  4. Deploy the stack:

    Terminal window
    pulumi up
    Previewing changes:
    ...
    Performing changes:
    ...
    info: 6 changes performed:
    + 6 resources created
    Update duration: 1m14s
  5. Test the deployed functions:

    Terminal window
    curl $(pulumi stack output pythonEndpoint)
    curl $(pulumi stack output goEndpoint)
    curl $(pulumi stack output tsEndpoint)
    "Hello World!"
    "Hello World!"
    "Hello World!"

Cleaning up#

Once you’re finished experimenting, destroy your stack and remove it to avoid incurring any additional cost:

Terminal window
pulumi destroy
pulumi stack rm

TypeScript notes#

In the typescriptfunc folder you’ll notice more than a function. Some configuration is needed to inform GCP how to build TypeScript for the Node.js runtime environment. See this example from Google for more details.

Related

The infrastructure as code platform for any cloud.