REST Resource: projects.locations.functions

Resource: Function

Describes a Cloud Function that contains user computation executed in response to an event. It encapsulate function and triggers configurations.

JSON representation
{
  "name": string,
  "environment": enum (Environment),
  "description": string,
  "buildConfig": {
    object (BuildConfig)
  },
  "serviceConfig": {
    object (ServiceConfig)
  },
  "eventTrigger": {
    object (EventTrigger)
  },
  "state": enum (State),
  "updateTime": string,
  "labels": {
    string: string,
    ...
  },
  "stateMessages": [
    {
      object (StateMessage)
    }
  ]
}
Fields
name

string

A user-defined name of the function. Function names must be unique globally and match pattern projects/*/locations/*/functions/*

environment

enum (Environment)

Describe whether the function is gen1 or gen2.

description

string

User-provided description of a function.

buildConfig

object (BuildConfig)

Describes the Build step of the function that builds a container from the given source.

serviceConfig

object (ServiceConfig)

Describes the Service being deployed. Currently deploys services to Cloud Run (fully managed).

eventTrigger

object (EventTrigger)

An Eventarc trigger managed by Google Cloud Functions that fires events in response to a condition in another service.

state

enum (State)

Output only. State of the function.

updateTime

string (Timestamp format)

Output only. The last update timestamp of a Cloud Function.

A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".

labels

map (key: string, value: string)

Labels associated with this Cloud Function.

An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.

stateMessages[]

object (StateMessage)

Output only. State Messages for this Cloud Function.

Environment

The environment the function is hosted on.

Enums
ENVIRONMENT_UNSPECIFIED Unspecified
GEN_1 Gen 1
GEN_2 Gen 2

BuildConfig

Describes the Build step of the function that builds a container from the given source.

JSON representation
{
  "build": string,
  "runtime": string,
  "entryPoint": string,
  "source": {
    object (Source)
  },
  "sourceProvenance": {
    object (SourceProvenance)
  },
  "workerPool": string,
  "environmentVariables": {
    string: string,
    ...
  },
  "dockerRepository": string
}
Fields
build

string

Output only. The Cloud Build name of the latest successful deployment of the function.

runtime

string

The runtime in which to run the function. Required when deploying a new function, optional when updating an existing function. For a complete list of possible choices, see the gcloud command reference.

entryPoint

string

The name of the function (as defined in source code) that will be executed. Defaults to the resource name suffix, if not specified. For backward compatibility, if function with given name is not found, then the system will try to use function named "function". For Node.js this is name of a function exported by the module specified in source_location.

source

object (Source)

The location of the function source code.

sourceProvenance

object (SourceProvenance)

Output only. A permanent fixed identifier for source.

workerPool

string

Name of the Cloud Build Custom Worker Pool that should be used to build the function. The format of this field is projects/{project}/locations/{region}/workerPools/{workerPool} where {project} and {region} are the project id and region respectively where the worker pool is defined and {workerPool} is the short name of the worker pool.

If the project id is not the same as the function, then the Cloud Functions Service Agent (service-@gcf-admin-robot.iam.gserviceaccount.com) must be granted the role Cloud Build Custom Workers Builder (roles/cloudbuild.customworkers.builder) in the project.

environmentVariables

map (key: string, value: string)

User-provided build-time environment variables for the function

An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.

dockerRepository

string

Optional. User managed repository created in Artifact Registry optionally with a customer managed encryption key. This is the repository to which the function docker image will be pushed after it is built by Cloud Build. If unspecified, GCF will create and use a repository named 'gcf-artifacts' for every deployed region.

It must match the pattern projects/{project}/locations/{location}/repositories/{repository}.

Cross-project repositories are not supported. Cross-location repositories are not supported. Repository format must be 'DOCKER'.

Source

The location of the function source code.

JSON representation
{

  // Union field source can be only one of the following:
  "storageSource": {
    object (StorageSource)
  },
  "repoSource": {
    object (RepoSource)
  }
  // End of list of possible types for union field source.
}
Fields
Union field source. Location of the source. At least one source needs to be provided for the deployment to succeed. source can be only one of the following:
storageSource

object (StorageSource)

If provided, get the source from this location in Google Cloud Storage.

repoSource

object (RepoSource)

If provided, get the source from this location in a Cloud Source Repository.

StorageSource

Location of the source in an archive file in Google Cloud Storage.

JSON representation
{
  "bucket": string,
  "object": string,
  "generation": string
}
Fields
bucket

string

Google Cloud Storage bucket containing the source (see Bucket Name Requirements).

object

string

Google Cloud Storage object containing the source.

This object must be a gzipped archive file (.tar.gz) containing source to build.

generation

string (int64 format)

Google Cloud Storage generation for the object. If the generation is omitted, the latest generation will be used.

RepoSource

Location of the source in a Google Cloud Source Repository.

JSON representation
{
  "projectId": string,
  "repoName": string,
  "dir": string,
  "invertRegex": boolean,

  // Union field revision can be only one of the following:
  "branchName": string,
  "tagName": string,
  "commitSha": string
  // End of list of possible types for union field revision.
}
Fields
projectId

string

ID of the project that owns the Cloud Source Repository. If omitted, the project ID requesting the build is assumed.

repoName

string

Name of the Cloud Source Repository.

dir

string

Directory, relative to the source root, in which to run the build.

This must be a relative path. If a step's dir is specified and is an absolute path, this value is ignored for that step's execution. eg. helloworld (no leading slash allowed)

invertRegex

boolean

Only trigger a build if the revision regex does NOT match the revision regex.

Union field revision. A revision within the Cloud Source Repository must be specified in one of these ways. revision can be only one of the following:
branchName

string

Regex matching branches to build.

The syntax of the regular expressions accepted is the syntax accepted by RE2 and described at https://github.com/google/re2/wiki/Syntax

tagName

string

Regex matching tags to build.

The syntax of the regular expressions accepted is the syntax accepted by RE2 and described at https://github.com/google/re2/wiki/Syntax

commitSha

string

Explicit commit SHA to build.

SourceProvenance

Provenance of the source. Ways to find the original source, or verify that some source was used for this build.

JSON representation
{
  "resolvedStorageSource": {
    object (StorageSource)
  },
  "resolvedRepoSource": {
    object (RepoSource)
  }
}
Fields
resolvedStorageSource

object (StorageSource)

A copy of the build's source.storage_source, if exists, with any generations resolved.

resolvedRepoSource

object (RepoSource)

A copy of the build's source.repo_source, if exists, with any revisions resolved.

ServiceConfig

Describes the Service being deployed. Currently Supported : Cloud Run (fully managed).

JSON representation
{
  "service": string,
  "timeoutSeconds": integer,
  "availableMemory": string,
  "environmentVariables": {
    string: string,
    ...
  },
  "maxInstanceCount": integer,
  "minInstanceCount": integer,
  "vpcConnector": string,
  "vpcConnectorEgressSettings": enum (VpcConnectorEgressSettings),
  "ingressSettings": enum (IngressSettings),
  "uri": string,
  "serviceAccountEmail": string,
  "allTrafficOnLatestRevision": boolean
}
Fields
service

string

Output only. Name of the service associated with a Function. The format of this field is projects/{project}/locations/{region}/services/{service}

timeoutSeconds

integer

The function execution timeout. Execution is considered failed and can be terminated if the function is not completed at the end of the timeout period. Defaults to 60 seconds.

availableMemory

string

The amount of memory available for a function. Defaults to 256M. Supported units are k, M, G, Mi, Gi. If no unit is supplied the value is interpreted as bytes. See https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/api/resource/quantity.go a full description.

environmentVariables

map (key: string, value: string)

Environment variables that shall be available during function execution.

An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.

maxInstanceCount

integer

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

In some cases, such as rapid traffic surges, Cloud Functions may, for a short period of time, create more instances than the specified max instances limit. If your function cannot tolerate this temporary behavior, you may want to factor in a safety margin and set a lower max instances value than your function can tolerate.

See the Max Instances Guide for more details.

minInstanceCount

integer

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

Function instances are kept in idle state for a short period after they finished executing the request to reduce cold start time for subsequent requests. Setting a minimum instance count will ensure that the given number of instances are kept running in idle state always. This can help with cold start times when jump in incoming request count occurs after the idle instance would have been stopped in the default case.

vpcConnector

string

The Serverless VPC Access connector that this cloud function can connect to. The format of this field is projects/*/locations/*/connectors/*.

vpcConnectorEgressSettings

enum (VpcConnectorEgressSettings)

The egress settings for the connector, controlling what traffic is diverted through it.

ingressSettings

enum (IngressSettings)

The ingress settings for the function, controlling what traffic can reach it.

uri

string

Output only. URI of the Service deployed.

serviceAccountEmail

string

The email of the service's service account. If empty, defaults to {project_number}-compute@developer.gserviceaccount.com.

allTrafficOnLatestRevision

boolean

Whether 100% of traffic is routed to the latest revision. On functions.create and functions.patch, when set to true, the revision being deployed will serve 100% of traffic, ignoring any traffic split settings, if any. On functions.get, true will be returned if the latest revision is serving 100% of traffic.

VpcConnectorEgressSettings

Available egress settings.

This controls what traffic is diverted through the VPC Access Connector resource. By default PRIVATE_RANGES_ONLY will be used.

Enums
VPC_CONNECTOR_EGRESS_SETTINGS_UNSPECIFIED Unspecified.
PRIVATE_RANGES_ONLY Use the VPC Access Connector only for private IP space from RFC1918.
ALL_TRAFFIC Force the use of VPC Access Connector for all egress traffic from the function.

IngressSettings

Available ingress settings.

This controls what traffic can reach the function.

If unspecified, ALLOW_ALL will be used.

Enums
INGRESS_SETTINGS_UNSPECIFIED Unspecified.
ALLOW_ALL Allow HTTP traffic from public and private sources.
ALLOW_INTERNAL_ONLY Allow HTTP traffic from only private VPC sources.
ALLOW_INTERNAL_AND_GCLB Allow HTTP traffic from private VPC sources and through GCLB.

EventTrigger

Describes EventTrigger, used to request events to be sent from another service.

JSON representation
{
  "trigger": string,
  "triggerRegion": string,
  "eventType": string,
  "eventFilters": [
    {
      object (EventFilter)
    }
  ],
  "pubsubTopic": string,
  "serviceAccountEmail": string,
  "retryPolicy": enum (RetryPolicy)
}
Fields
trigger

string

Output only. The resource name of the Eventarc trigger. The format of this field is projects/{project}/locations/{region}/triggers/{trigger}.

triggerRegion

string

The region that the trigger will be in. The trigger will only receive events originating in this region. It can be the same region as the function, a different region or multi-region, or the global region. If not provided, defaults to the same region as the function.

eventType

string

Required. The type of event to observe. For example: google.cloud.audit.log.v1.written or google.cloud.pubsub.topic.v1.messagePublished.

eventFilters[]

object (EventFilter)

Criteria used to filter events.

pubsubTopic

string

Optional. The name of a Pub/Sub topic in the same project that will be used as the transport topic for the event delivery. Format: projects/{project}/topics/{topic}.

This is only valid for events of type google.cloud.pubsub.topic.v1.messagePublished. The topic provided here will not be deleted at function deletion.

serviceAccountEmail

string

Optional. The email of the trigger's service account. The service account must have permission to invoke Cloud Run services, the permission is run.routes.invoke. If empty, defaults to the Compute Engine default service account: {project_number}-compute@developer.gserviceaccount.com.

retryPolicy

enum (RetryPolicy)

Optional. If unset, then defaults to ignoring failures (i.e. not retrying them).

EventFilter

Filters events based on exact matches on the CloudEvents attributes.

JSON representation
{
  "attribute": string,
  "value": string
}
Fields
attribute

string

Required. The name of a CloudEvents attribute.

value

string

Required. The value for the attribute.

RetryPolicy

Describes the retry policy in case of function's execution failure. Retried execution is charged as any other execution.

Enums
RETRY_POLICY_UNSPECIFIED Not specified.
RETRY_POLICY_DO_NOT_RETRY Do not retry.
RETRY_POLICY_RETRY Retry on any failure, retry up to 7 days with an exponential backoff (capped at 10 seconds).

State

Describes the current state of the function.

Enums
STATE_UNSPECIFIED Not specified. Invalid state.
ACTIVE Function has been successfully deployed and is serving.
FAILED Function deployment failed and the function is not serving.
DEPLOYING Function is being created or updated.
DELETING Function is being deleted.
UNKNOWN Function deployment failed and the function serving state is undefined. The function should be updated or deleted to move it out of this state.

StateMessage

Informational messages about the state of the Cloud Function or Operation.

JSON representation
{
  "severity": enum (Severity),
  "type": string,
  "message": string
}
Fields
severity

enum (Severity)

Severity of the state message.

type

string

One-word CamelCase type of the state message.

message

string

The message.

Severity

Severity of the state message.

Enums
SEVERITY_UNSPECIFIED Not specified. Invalid severity.
ERROR ERROR-level severity.
WARNING WARNING-level severity.
INFO INFO-level severity.

Methods

create

Creates a new function.

delete

Deletes a function with the given name from the specified project.

generateDownloadUrl

Returns a signed URL for downloading deployed function source code.

generateUploadUrl

Returns a signed URL for uploading a function source code.

get

Returns a function with the given name from the requested project.

getIamPolicy

Gets the access control policy for a resource.

list

Returns a list of functions that belong to the requested project.

patch

Updates existing function.

setIamPolicy

Sets the access control policy on the specified resource.

testIamPermissions

Returns permissions that a caller has on the specified resource.