Module cloudfunctions

@pulumi/gcp > cloudfunctions

class CallbackFunction

extends ComponentResource

A CallbackFunction is a special type of gcp.cloudfunctions.Function that can be created out of an actual JavaScript function instance. The function instance will be analyzed and packaged up (including dependencies) into a form that can be used by Cloud Functions. See https://github.com/pulumi/docs/blob/master/reference/serializing-functions.md for additional details on this process.

Note: CallbackFunctions create Google Cloud Functions that uses the [nodejs8] runtime. Importantly, calls follow the (data, context) => ... form, not the (event, callback) => ... form that is used with the [nodejs6] runtime. This also adds support for asynchronous functions as well. See https://cloud.google.com/functions/docs/writing/background#functions_background_parameters-node8 for more details.

constructor

new CallbackFunction(name: string, args: CallbackFunctionArgs, opts: pulumi.ComponentResourceOptions)

method getProvider

getProvider(moduleMember: string): ProviderResource | undefined

method isInstance

static isInstance(obj: any): boolean

Returns true if the given object is an instance of CustomResource. This is designed to work even when multiple copies of the Pulumi SDK have been loaded into the same process.

method registerOutputs

protected registerOutputs(outputs?: Inputs | Promise<Inputs> | Output<Inputs>): void

property bucket

public bucket: storage.Bucket;

Bucket and BucketObject storing all the files that comprise the Function. The contents of these files will be generated automatically from the JavaScript callback function passed in as well as the package.json file for your pulumi app.

property bucketObject

public bucketObject: storage.BucketObject;

property function

public function: cloudfunctions.Function;

Underlying raw resource for the Function that is created.

property urn

urn: Output<URN>;

urn is the stable logical URN used to distinctly address a resource, both before and after deployments.

class Function

extends CustomResource

Creates a new Cloud Function. For more information see the official documentation and API.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const bucket = new gcp.storage.Bucket("bucket", {});
const archive = new gcp.storage.BucketObject("archive", {
    bucket: bucket.name,
    source: new pulumi.asset.FileArchive("./path/to/zip/file/which/contains/code"),
});
const functionFunction = new gcp.cloudfunctions.Function("function", {
    availableMemoryMb: 128,
    description: "My function",
    entryPoint: "helloGET",
    environmentVariables: {
        MY_ENV_VAR: "my-env-var-value",
    },
    labels: {
        "my-label": "my-label-value",
    },
    runtime: "nodejs10",
    sourceArchiveBucket: bucket.name,
    sourceArchiveObject: archive.name,
    timeout: 60,
    triggerHttp: true,
});

constructor

new Function(name: string, args?: FunctionArgs, opts?: pulumi.CustomResourceOptions)

Create a Function resource with the given unique name, arguments, and options.

  • name The unique name of the resource.
  • args The arguments to use to populate this resource's properties.
  • opts A bag of options that control this resource's behavior.

method get

public static get(name: string, id: pulumi.Input<pulumi.ID>, state?: FunctionState, opts?: pulumi.CustomResourceOptions): Function

Get an existing Function resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

method getProvider

getProvider(moduleMember: string): ProviderResource | undefined

method isInstance

static isInstance(obj: any): boolean

Returns true if the given object is an instance of CustomResource. This is designed to work even when multiple copies of the Pulumi SDK have been loaded into the same process.

property availableMemoryMb

public availableMemoryMb: pulumi.Output<number | undefined>;

Memory (in MB), available to the function. Default value is 256MB. Allowed values are: 128MB, 256MB, 512MB, 1024MB, and 2048MB.

property description

public description: pulumi.Output<string | undefined>;

Description of the function.

property entryPoint

public entryPoint: pulumi.Output<string | undefined>;

Name of the function that will be executed when the Google Cloud Function is triggered.

property environmentVariables

public environmentVariables: pulumi.Output<{[key: string]: any} | undefined>;

A set of key/value environment variable pairs to assign to the function.

property eventTrigger

public eventTrigger: pulumi.Output<{
    eventType: string;
    failurePolicy: {
        retry: boolean;
    };
    resource: string;
}>;

A source that fires events in response to a condition in another service. Structure is documented below. Cannot be used with trigger_http.

property httpsTriggerUrl

public httpsTriggerUrl: pulumi.Output<string>;

URL which triggers function execution. Returned only if trigger_http is used.

property id

id: Output<ID>;

id is the provider-assigned unique ID for this managed resource. It is set during deployments and may be missing (undefined) during planning phases.

property labels

public labels: pulumi.Output<{[key: string]: any} | undefined>;

A set of key/value label pairs to assign to the function.

property maxInstances

public maxInstances: pulumi.Output<number | undefined>;

The limit on the maximum number of function instances that may coexist at a given time.

property name

public name: pulumi.Output<string>;

A user-defined name of the function. Function names must be unique globally.

property project

public project: pulumi.Output<string>;

Project of the function. If it is not provided, the provider project is used.

property region

public region: pulumi.Output<string>;

Region of function. Currently can be only “us-central1”. If it is not provided, the provider region is used.

property runtime

public runtime: pulumi.Output<string | undefined>;

The runtime in which the function is going to run. One of "nodejs6", "nodejs8", "nodejs10", "python37", "go111". If empty, defaults to "nodejs6". It’s recommended that you override the default, as "nodejs6" is deprecated.

property serviceAccountEmail

public serviceAccountEmail: pulumi.Output<string>;

If provided, the self-provided service account to run the function with.

property sourceArchiveBucket

public sourceArchiveBucket: pulumi.Output<string | undefined>;

The GCS bucket containing the zip archive which contains the function.

property sourceArchiveObject

public sourceArchiveObject: pulumi.Output<string | undefined>;

The source archive object (file) in archive bucket.

property sourceRepository

public sourceRepository: pulumi.Output<{
    deployedUrl: string;
    url: string;
} | undefined>;

Represents parameters related to source repository where a function is hosted. Cannot be set alongside source_archive_bucket or source_archive_object. Structure is documented below.

property timeout

public timeout: pulumi.Output<number | undefined>;

Timeout (in seconds) for the function. Default value is 60 seconds. Cannot be more than 540 seconds.

property triggerHttp

public triggerHttp: pulumi.Output<boolean | undefined>;

Boolean variable. Any HTTP request (of a supported type) to the endpoint will trigger function execution. Supported HTTP request types are: POST, PUT, GET, DELETE, and OPTIONS. Endpoint is returned as https_trigger_url. Cannot be used with trigger_bucket and trigger_topic.

property urn

urn: Output<URN>;

urn is the stable logical URN used to distinctly address a resource, both before and after deployments.

class HttpCallbackFunction

extends CallbackFunction

An http-triggered Cloud-Function that, when invoked, will execute the code supplied by a user-provided JavaScript-Function. To handle HTTP, Cloud Functions uses Express 4.16.3.

You invoke HTTP functions from standard HTTP requests. These HTTP requests wait for the response and support handling of common HTTP request methods like GET, PUT, POST, DELETE and OPTIONS. When you use Cloud Functions, a TLS certificate is automatically provisioned for you, so all HTTP functions can be invoked via a secure connection.

See more information at: https://cloud.google.com/functions/docs/writing/http

constructor

new HttpCallbackFunction(name: string, callback: HttpCallback, opts?: pulumi.ComponentResourceOptions)
new HttpCallbackFunction(name: string, args: HttpCallbackFunctionArgs, opts?: pulumi.ComponentResourceOptions)

method getProvider

getProvider(moduleMember: string): ProviderResource | undefined

method isInstance

static isInstance(obj: any): boolean

Returns true if the given object is an instance of CustomResource. This is designed to work even when multiple copies of the Pulumi SDK have been loaded into the same process.

method registerOutputs

protected registerOutputs(outputs?: Inputs | Promise<Inputs> | Output<Inputs>): void

property bucket

public bucket: storage.Bucket;

Bucket and BucketObject storing all the files that comprise the Function. The contents of these files will be generated automatically from the JavaScript callback function passed in as well as the package.json file for your pulumi app.

property bucketObject

public bucketObject: storage.BucketObject;

property function

public function: cloudfunctions.Function;

Underlying raw resource for the Function that is created.

property httpsTriggerUrl

public httpsTriggerUrl: pulumi.Output<string>;

URL which triggers function execution.

property urn

urn: Output<URN>;

urn is the stable logical URN used to distinctly address a resource, both before and after deployments.

function getFunction

getFunction(args: GetFunctionArgs, opts?: pulumi.InvokeOptions): Promise<GetFunctionResult>

Get information about a Google Cloud Function. For more information see the official documentation and API.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const my_function = pulumi.output(gcp.cloudfunctions.getFunction({
    name: "function",
}));

interface CallbackFunctionArgs

Arguments that control both how a user function is serialized and how the final Cloud Function is created. Can be used to override values if the defaults are not desirable.

property availableMemoryMb

availableMemoryMb?: pulumi.Input<number>;

Memory (in MB), available to the function. Default value is 256MB. Allowed values are: 128MB, 256MB, 512MB, 1024MB, and 2048MB.

property bucket

bucket?: storage.Bucket;

The bucket to use as the sourceArchiveBucket for the generated CloudFunctions Function source to be placed in. A fresh [storage.BucketObject] will be made there containing the serialized code.

property callback

callback?: Function;

The Javascript callback to use as the entrypoint for the GCP CloudFunction out of. Either [callback] or [callbackFactory] must be provided.

property callbackFactory

callbackFactory?: Function;

The Javascript function instance that will be called to produce the callback function that is the entrypoint for the GCP Cloud Function. Either [callback] or [callbackFactory] must be provided.

This form is useful when there is expensive initialization work that should only be executed once. The factory-function will be invoked once when the final GCP Cloud Function module is loaded. It can run whatever code it needs, and will end by returning the actual function that Function will call into each time the Cloud Function is invoked.

property codePathOptions

codePathOptions?: pulumi.runtime.CodePathOptions;

Options to control which paths/packages should be included or excluded in the zip file containing the code for the GCP Function.

property description

description?: pulumi.Input<string>;

Description of the function.

property environmentVariables

environmentVariables?: pulumi.Input<{[key: string]: any}>;

A set of key/value environment variable pairs to assign to the function.

property eventTrigger

eventTrigger?: pulumi.Input<{
    eventType: pulumi.Input<string>;
    failurePolicy: pulumi.Input<FailurePolicy>;
    resource: pulumi.Input<string>;
}>;

A source that fires events in response to a condition in another service. Structure is documented below. Cannot be used with trigger_http.

property httpsTriggerUrl

httpsTriggerUrl?: pulumi.Input<string>;

URL which triggers function execution. Returned only if trigger_http is used.

property labels

labels?: pulumi.Input<{[key: string]: any}>;

A set of key/value label pairs to assign to the function.

property project

project?: pulumi.Input<string>;

Project of the function. If it is not provided, the provider project is used.

property region

region?: pulumi.Input<string>;

Region of function. Currently can be only “us-central1”. If it is not provided, the provider region is used.

property serviceAccountEmail

serviceAccountEmail?: pulumi.Input<string>;

If provided, the self-provided service account to run the function with.

property timeout

timeout?: pulumi.Input<number>;

Timeout (in seconds) for the function. Default value is 60 seconds. Cannot be more than 540 seconds.

property triggerHttp

triggerHttp?: pulumi.Input<boolean>;

Boolean variable. Any HTTP request (of a supported type) to the endpoint will trigger function execution. Supported HTTP request types are: POST, PUT, GET, DELETE, and OPTIONS. Endpoint is returned as https_trigger_url. Cannot be used with trigger_bucket and trigger_topic.

interface Context

Google Cloud Functions uses this parameter to provide details of your Function’s execution. For more information, see https://cloud.google.com/functions/docs/writing/background#function_parameters

property eventId

eventId: string;

A unique ID for the event. For example: “70172329041928”.

property eventType

eventType: string;

The type of the event. For example: “google.pubsub.topic.publish”.

property resource

resource: any;

The resource that emitted the event. See derived contexts for more specific information about the shape of this property.

property timestamp

timestamp: string;

The date/time this event was created. For example: “2018-04-09T07:56:12.975Z”.

interface FailurePolicy

Describes the policy in case of function’s execution failure. If empty, then defaults to ignoring failures (i.e. not retrying them).

property retry

retry: pulumi.Input<boolean>;

Whether the function should be retried on failure.

If true, a function execution will be retried on any failure. A failed execution will be retried up to 7 days with an exponential backoff (capped at 10 seconds). Retried execution is charged as any other execution.

interface FunctionArgs

The set of arguments for constructing a Function resource.

property availableMemoryMb

availableMemoryMb?: pulumi.Input<number>;

Memory (in MB), available to the function. Default value is 256MB. Allowed values are: 128MB, 256MB, 512MB, 1024MB, and 2048MB.

property description

description?: pulumi.Input<string>;

Description of the function.

property entryPoint

entryPoint?: pulumi.Input<string>;

Name of the function that will be executed when the Google Cloud Function is triggered.

property environmentVariables

environmentVariables?: pulumi.Input<{[key: string]: any}>;

A set of key/value environment variable pairs to assign to the function.

property eventTrigger

eventTrigger?: pulumi.Input<{
    eventType: pulumi.Input<string>;
    failurePolicy: pulumi.Input<{
        retry: pulumi.Input<boolean>;
    }>;
    resource: pulumi.Input<string>;
}>;

A source that fires events in response to a condition in another service. Structure is documented below. Cannot be used with trigger_http.

property httpsTriggerUrl

httpsTriggerUrl?: pulumi.Input<string>;

URL which triggers function execution. Returned only if trigger_http is used.

property labels

labels?: pulumi.Input<{[key: string]: any}>;

A set of key/value label pairs to assign to the function.

property maxInstances

maxInstances?: pulumi.Input<number>;

The limit on the maximum number of function instances that may coexist at a given time.

property name

name?: pulumi.Input<string>;

A user-defined name of the function. Function names must be unique globally.

property project

project?: pulumi.Input<string>;

Project of the function. If it is not provided, the provider project is used.

property region

region?: pulumi.Input<string>;

Region of function. Currently can be only “us-central1”. If it is not provided, the provider region is used.

property runtime

runtime?: pulumi.Input<string>;

The runtime in which the function is going to run. One of "nodejs6", "nodejs8", "nodejs10", "python37", "go111". If empty, defaults to "nodejs6". It’s recommended that you override the default, as "nodejs6" is deprecated.

property serviceAccountEmail

serviceAccountEmail?: pulumi.Input<string>;

If provided, the self-provided service account to run the function with.

property sourceArchiveBucket

sourceArchiveBucket?: pulumi.Input<string>;

The GCS bucket containing the zip archive which contains the function.

property sourceArchiveObject

sourceArchiveObject?: pulumi.Input<string>;

The source archive object (file) in archive bucket.

property sourceRepository

sourceRepository?: pulumi.Input<{
    deployedUrl: pulumi.Input<string>;
    url: pulumi.Input<string>;
}>;

Represents parameters related to source repository where a function is hosted. Cannot be set alongside source_archive_bucket or source_archive_object. Structure is documented below.

property timeout

timeout?: pulumi.Input<number>;

Timeout (in seconds) for the function. Default value is 60 seconds. Cannot be more than 540 seconds.

property triggerHttp

triggerHttp?: pulumi.Input<boolean>;

Boolean variable. Any HTTP request (of a supported type) to the endpoint will trigger function execution. Supported HTTP request types are: POST, PUT, GET, DELETE, and OPTIONS. Endpoint is returned as https_trigger_url. Cannot be used with trigger_bucket and trigger_topic.

interface FunctionState

Input properties used for looking up and filtering Function resources.

property availableMemoryMb

availableMemoryMb?: pulumi.Input<number>;

Memory (in MB), available to the function. Default value is 256MB. Allowed values are: 128MB, 256MB, 512MB, 1024MB, and 2048MB.

property description

description?: pulumi.Input<string>;

Description of the function.

property entryPoint

entryPoint?: pulumi.Input<string>;

Name of the function that will be executed when the Google Cloud Function is triggered.

property environmentVariables

environmentVariables?: pulumi.Input<{[key: string]: any}>;

A set of key/value environment variable pairs to assign to the function.

property eventTrigger

eventTrigger?: pulumi.Input<{
    eventType: pulumi.Input<string>;
    failurePolicy: pulumi.Input<{
        retry: pulumi.Input<boolean>;
    }>;
    resource: pulumi.Input<string>;
}>;

A source that fires events in response to a condition in another service. Structure is documented below. Cannot be used with trigger_http.

property httpsTriggerUrl

httpsTriggerUrl?: pulumi.Input<string>;

URL which triggers function execution. Returned only if trigger_http is used.

property labels

labels?: pulumi.Input<{[key: string]: any}>;

A set of key/value label pairs to assign to the function.

property maxInstances

maxInstances?: pulumi.Input<number>;

The limit on the maximum number of function instances that may coexist at a given time.

property name

name?: pulumi.Input<string>;

A user-defined name of the function. Function names must be unique globally.

property project

project?: pulumi.Input<string>;

Project of the function. If it is not provided, the provider project is used.

property region

region?: pulumi.Input<string>;

Region of function. Currently can be only “us-central1”. If it is not provided, the provider region is used.

property runtime

runtime?: pulumi.Input<string>;

The runtime in which the function is going to run. One of "nodejs6", "nodejs8", "nodejs10", "python37", "go111". If empty, defaults to "nodejs6". It’s recommended that you override the default, as "nodejs6" is deprecated.

property serviceAccountEmail

serviceAccountEmail?: pulumi.Input<string>;

If provided, the self-provided service account to run the function with.

property sourceArchiveBucket

sourceArchiveBucket?: pulumi.Input<string>;

The GCS bucket containing the zip archive which contains the function.

property sourceArchiveObject

sourceArchiveObject?: pulumi.Input<string>;

The source archive object (file) in archive bucket.

property sourceRepository

sourceRepository?: pulumi.Input<{
    deployedUrl: pulumi.Input<string>;
    url: pulumi.Input<string>;
}>;

Represents parameters related to source repository where a function is hosted. Cannot be set alongside source_archive_bucket or source_archive_object. Structure is documented below.

property timeout

timeout?: pulumi.Input<number>;

Timeout (in seconds) for the function. Default value is 60 seconds. Cannot be more than 540 seconds.

property triggerHttp

triggerHttp?: pulumi.Input<boolean>;

Boolean variable. Any HTTP request (of a supported type) to the endpoint will trigger function execution. Supported HTTP request types are: POST, PUT, GET, DELETE, and OPTIONS. Endpoint is returned as https_trigger_url. Cannot be used with trigger_bucket and trigger_topic.

interface GetFunctionArgs

A collection of arguments for invoking getFunction.

property name

name: string;

The name of a Cloud Function.

property project

project?: undefined | string;

The project in which the resource belongs. If it is not provided, the provider project is used.

property region

region?: undefined | string;

The region in which the resource belongs. If it is not provided, the provider region is used.

interface GetFunctionResult

A collection of values returned by getFunction.

property availableMemoryMb

availableMemoryMb: number;

Available memory (in MB) to the function.

property description

description: string;

Description of the function.

property entryPoint

entryPoint: string;

Name of a JavaScript function that will be executed when the Google Cloud Function is triggered.

property environmentVariables

environmentVariables: {[key: string]: any};

property eventTriggers

eventTriggers: {
    eventType: string;
    failurePolicies: {
        retry: boolean;
    }[];
    resource: string;
}[];

A source that fires events in response to a condition in another service. Structure is documented below.

property httpsTriggerUrl

httpsTriggerUrl: string;

If function is triggered by HTTP, trigger URL is set here.

property id

id: string;

id is the provider-assigned unique ID for this managed resource.

property labels

labels: {[key: string]: any};

A map of labels applied to this function.

property maxInstances

maxInstances: number;

property name

name: string;

The name of the Cloud Function.

property project

project?: undefined | string;

property region

region?: undefined | string;

property runtime

runtime: string;

The runtime in which the function is running.

property serviceAccountEmail

serviceAccountEmail: string;

property sourceArchiveBucket

sourceArchiveBucket: string;

The GCS bucket containing the zip archive which contains the function.

property sourceArchiveObject

sourceArchiveObject: string;

The source archive object (file) in archive bucket.

property sourceRepositories

sourceRepositories: {
    deployedUrl: string;
    url: string;
}[];

property timeout

timeout: number;

Function execution timeout (in seconds).

property triggerBucket

triggerBucket: string;

property triggerHttp

triggerHttp: boolean;

If function is triggered by HTTP, this boolean is set.

property triggerTopic

triggerTopic: string;

interface HttpCallbackFunctionArgs

extends CallbackFunctionArgs

Specialized arguments to use when specifically creating an [HttpCallbackFunction].

property availableMemoryMb

availableMemoryMb?: pulumi.Input<number>;

Memory (in MB), available to the function. Default value is 256MB. Allowed values are: 128MB, 256MB, 512MB, 1024MB, and 2048MB.

property bucket

bucket?: storage.Bucket;

The bucket to use as the sourceArchiveBucket for the generated CloudFunctions Function source to be placed in. A fresh [storage.BucketObject] will be made there containing the serialized code.

property callback

callback?: HttpCallback;

The Javascript callback to use as the entrypoint for the GCP CloudFunction out of. Either [callback] or [callbackFactory] must be provided.

property callbackFactory

callbackFactory?: HttpCallbackFactory;

The Javascript function instance that will be called to produce the callback function that is the entrypoint for the GCP CloudFunction. Either [callback] or [callbackFactory] must be provided.

This form is useful when there is expensive initialization work that should only be executed once. The factory-function will be invoked once when the final GCP CloudFunction module is loaded. It can run whatever code it needs, and will end by returning the actual function that Function will call into each time the Function is invoked.

property codePathOptions

codePathOptions?: pulumi.runtime.CodePathOptions;

Options to control which paths/packages should be included or excluded in the zip file containing the code for the GCP Function.

property description

description?: pulumi.Input<string>;

Description of the function.

property environmentVariables

environmentVariables?: pulumi.Input<{[key: string]: any}>;

A set of key/value environment variable pairs to assign to the function.

property eventTrigger

eventTrigger?: undefined;

property httpsTriggerUrl

httpsTriggerUrl?: pulumi.Input<string>;

URL which triggers function execution. Returned only if trigger_http is used.

property labels

labels?: pulumi.Input<{[key: string]: any}>;

A set of key/value label pairs to assign to the function.

property project

project?: pulumi.Input<string>;

Project of the function. If it is not provided, the provider project is used.

property region

region?: pulumi.Input<string>;

Region of function. Currently can be only “us-central1”. If it is not provided, the provider region is used.

property serviceAccountEmail

serviceAccountEmail?: pulumi.Input<string>;

If provided, the self-provided service account to run the function with.

property timeout

timeout?: pulumi.Input<number>;

Timeout (in seconds) for the function. Default value is 60 seconds. Cannot be more than 540 seconds.

property triggerHttp

triggerHttp?: undefined;

type Callback

type Callback = (data: D, context: C, callback: (error?: any, result?: R) => void) => Promise<R> | void;

Callback is the signature for an Google Cloud Function entrypoint.

[data] is the data passed in by specific services calling the Function (like storage, or pubsub). The shape of it will be specific to individual services.

[context] Cloud Functions uses this parameter to provide details of your Function’s execution. For more information, see https://cloud.google.com/functions/docs/writing/background#function_parameters

[callback] A callback to signal completion of the function’s execution. Follows the “errback” convention, which interprets the first argument as an error.

You must signal when background functions have completed. Otherwise, your function can continue to run and be forcibly terminated by the system. You can signal function completion by:

  1. Invoking the callback argument,
  2. Returning a Promise,
  3. Wrapping your function using the async keyword (which causes your function to implicitly return a Promise), or
  4. Returning a value.

If invoking the callback argument or synchronously returning a value, ensure that all asynchronous processes have completed first. If returning a Promise, Cloud Functions ensures that the Promise is settled before terminating.

type CallbackFactory

type CallbackFactory = () => Callback<D, C, R>;

CallbackFactory is the signature for a function that will be called once to produce the entrypoint function that GCP Cloud Function will invoke. It can be used to initialize expensive state once that can then be used across all invocations of the Function (as long as the Function is using the same warm node instance).

type HttpCallback

type HttpCallback = (req: express.Request, res: express.Response) => void;

HttpCallback is the signature for an http triggered GCP CloudFunction entrypoint.

[req] is the data passed in by specific services calling the CloudFunction. See https://expressjs.com/en/api.html#req for more details.

[res] is the object that be used to supply the response. See https://expressjs.com/en/api.html#res for more details.

type HttpCallbackFactory

type HttpCallbackFactory = () => HttpCallback;