Google Cloud Functions V1 Client - Class CloudFunction (1.2.0)

Reference documentation and code samples for the Google Cloud Functions V1 Client class CloudFunction.

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

Generated from protobuf message google.cloud.functions.v1.CloudFunction

Methods

__construct

Constructor.

Parameters
NameDescription
data array

Optional. Data for populating the Message object.

↳ name string

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

↳ description string

User-provided description of a function.

↳ source_archive_url string

The Google Cloud Storage URL, starting with gs://, pointing to the zip archive which contains the function.

↳ source_repository Google\Cloud\Functions\V1\SourceRepository

Beta Feature The source repository where a function is hosted.

↳ source_upload_url string

The Google Cloud Storage-signed URL used for source uploading, generated by calling [google.cloud.functions.v1.GenerateUploadUrl]. The signature is validated on write methods (Create, Update) The signature is stripped from the Function object on read methods (Get, List)

↳ https_trigger Google\Cloud\Functions\V1\HttpsTrigger

An HTTPS endpoint type of source that can be triggered via URL.

↳ event_trigger Google\Cloud\Functions\V1\EventTrigger

A source that fires events in response to a condition in another service.

↳ status int

Output only. Status of the function deployment.

↳ entry_point string

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

↳ 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.

↳ timeout Google\Protobuf\Duration

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.

↳ available_memory_mb int

The amount of memory in MB available for a function. Defaults to 256MB.

↳ service_account_email string

The email of the function's service account. If empty, defaults to {project_id}@appspot.gserviceaccount.com.

↳ update_time Google\Protobuf\Timestamp

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

↳ version_id int|string

Output only. The version identifier of the Cloud Function. Each deployment attempt results in a new version of a function being created.

↳ labels array|Google\Protobuf\Internal\MapField

Labels associated with this Cloud Function.

↳ environment_variables array|Google\Protobuf\Internal\MapField

Environment variables that shall be available during function execution.

↳ build_environment_variables array|Google\Protobuf\Internal\MapField

Build environment variables that shall be available during build time.

↳ network string

The Serverless VPC Access connector that this cloud function can connect to. It can be either the fully qualified URI, or the short name of the connector resource. If the connector name is used, the connector must belong to the same project as the function. Otherwise, it must belong to a project within the same organization. The format of this field is either projects/{project}/global/networks/{network} or {network}, where {project} is a project id where the network is defined, and {network} is the short name of the network. This field is mutually exclusive with vpc_connector and will be replaced by it. See the VPC documentation for more information on connecting Cloud projects.

↳ max_instances int

The limit on the maximum number of function instances that can coexist at a given time. In some cases, such as rapid traffic surges, Cloud Functions can for a short period of time create more instances than the specified max instances limit. If your function cannot tolerate this temporary behavior, you might 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.

↳ min_instances int

A lower bound for the number function instances that can coexist at a given time.

↳ vpc_connector string

The VPC Network Connector that this cloud function can connect to. It can be either the fully qualified URI, or the short name of the network connector resource. The format of this field is projects/*/locations/*/connectors/* This field is mutually exclusive with network field and will eventually replace it. See the VPC documentation for more information on connecting Cloud projects.

↳ vpc_connector_egress_settings int

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

↳ ingress_settings int

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

↳ kms_key_name string

Resource name of a KMS crypto key (managed by the user) used to encrypt/decrypt function resources. It must match the pattern projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}. If specified, you must also provide an artifact registry repository using the docker_repository field that was created with the same KMS crypto key. The following service accounts need to be granted the role 'Cloud KMS CryptoKey Encrypter/Decrypter (roles/cloudkms.cryptoKeyEncrypterDecrypter)' on the Key/KeyRing/Project/Organization (least access preferred). 1. Google Cloud Functions service account (service-{project_number}@gcf-admin-robot.iam.gserviceaccount.com) - Required to protect the function's image. 2. Google Storage service account (service-{project_number}@gs-project-accounts.iam.gserviceaccount.com) - Required to protect the function's source code. If this service account does not exist, deploying a function without a KMS key or retrieving the service agent name provisions it. For more information, see https://cloud.google.com/storage/docs/projects#service-agents and https://cloud.google.com/storage/docs/getting-service-agent#gsutil. Google Cloud Functions delegates access to service agents to protect function resources in internal projects that are not accessible by the end user.

↳ build_worker_pool 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-<project_number>@gcf-admin-robot.iam.gserviceaccount.com) must be granted the role Cloud Build Custom Workers Builder (roles/cloudbuild.customworkers.builder) in the project.

↳ build_id string

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

↳ build_name string

Output only. The Cloud Build Name of the function deployment. projects/<project-number>/locations/<region>/builds/<build-id>.

↳ secret_environment_variables array<Google\Cloud\Functions\V1\SecretEnvVar>

Secret environment variables configuration.

↳ secret_volumes array<Google\Cloud\Functions\V1\SecretVolume>

Secret volumes configuration.

↳ source_token string

Input only. An identifier for Firebase function sources. Disclaimer: This field is only supported for Firebase function deployments.

↳ docker_repository string

User managed repository created in Artifact Registry optionally with a customer managed encryption key. If specified, deployments will use Artifact Registry. If unspecified and the deployment is eligible to use Artifact Registry, GCF will create and use a repository named 'gcf-artifacts' for every deployed region. This is the repository to which the function docker image is pushed after it is built by Cloud Build. 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'.

↳ docker_registry int

Docker Registry to use for this deployment. If docker_repository field is specified, this field is automatically set as ARTIFACT_REGISTRY. If unspecified, it currently defaults to CONTAINER_REGISTRY. This field may be overridden by the backend for eligible deployments.

getName

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

Returns
TypeDescription
string

setName

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

Parameter
NameDescription
var string
Returns
TypeDescription
$this

getDescription

User-provided description of a function.

Returns
TypeDescription
string

setDescription

User-provided description of a function.

Parameter
NameDescription
var string
Returns
TypeDescription
$this

getSourceArchiveUrl

The Google Cloud Storage URL, starting with gs://, pointing to the zip archive which contains the function.

Returns
TypeDescription
string

hasSourceArchiveUrl

setSourceArchiveUrl

The Google Cloud Storage URL, starting with gs://, pointing to the zip archive which contains the function.

Parameter
NameDescription
var string
Returns
TypeDescription
$this

getSourceRepository

Beta Feature The source repository where a function is hosted.

Returns
TypeDescription
Google\Cloud\Functions\V1\SourceRepository|null

hasSourceRepository

setSourceRepository

Beta Feature The source repository where a function is hosted.

Parameter
NameDescription
var Google\Cloud\Functions\V1\SourceRepository
Returns
TypeDescription
$this

getSourceUploadUrl

The Google Cloud Storage-signed URL used for source uploading, generated by calling [google.cloud.functions.v1.GenerateUploadUrl].

The signature is validated on write methods (Create, Update) The signature is stripped from the Function object on read methods (Get, List)

Returns
TypeDescription
string

hasSourceUploadUrl

setSourceUploadUrl

The Google Cloud Storage-signed URL used for source uploading, generated by calling [google.cloud.functions.v1.GenerateUploadUrl].

The signature is validated on write methods (Create, Update) The signature is stripped from the Function object on read methods (Get, List)

Parameter
NameDescription
var string
Returns
TypeDescription
$this

getHttpsTrigger

An HTTPS endpoint type of source that can be triggered via URL.

Returns
TypeDescription
Google\Cloud\Functions\V1\HttpsTrigger|null

hasHttpsTrigger

setHttpsTrigger

An HTTPS endpoint type of source that can be triggered via URL.

Parameter
NameDescription
var Google\Cloud\Functions\V1\HttpsTrigger
Returns
TypeDescription
$this

getEventTrigger

A source that fires events in response to a condition in another service.

Returns
TypeDescription
Google\Cloud\Functions\V1\EventTrigger|null

hasEventTrigger

setEventTrigger

A source that fires events in response to a condition in another service.

Parameter
NameDescription
var Google\Cloud\Functions\V1\EventTrigger
Returns
TypeDescription
$this

getStatus

Output only. Status of the function deployment.

Returns
TypeDescription
int

setStatus

Output only. Status of the function deployment.

Parameter
NameDescription
var int
Returns
TypeDescription
$this

getEntryPoint

The name of the function (as defined in source code) that is executed.

Defaults to the resource name suffix, if not specified. For backward compatibility, if function with given name is not found, the system tries to use the function named "function". For Node.js, this is the name of a function exported by the module as specified in source_location.

Returns
TypeDescription
string

setEntryPoint

The name of the function (as defined in source code) that is executed.

Defaults to the resource name suffix, if not specified. For backward compatibility, if function with given name is not found, the system tries to use the function named "function". For Node.js, this is the name of a function exported by the module as specified in source_location.

Parameter
NameDescription
var string
Returns
TypeDescription
$this

getRuntime

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.

Returns
TypeDescription
string

setRuntime

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.

Parameter
NameDescription
var string
Returns
TypeDescription
$this

getTimeout

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.

Returns
TypeDescription
Google\Protobuf\Duration|null

hasTimeout

clearTimeout

setTimeout

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.

Parameter
NameDescription
var Google\Protobuf\Duration
Returns
TypeDescription
$this

getAvailableMemoryMb

The amount of memory in MB available for a function.

Defaults to 256MB.

Returns
TypeDescription
int

setAvailableMemoryMb

The amount of memory in MB available for a function.

Defaults to 256MB.

Parameter
NameDescription
var int
Returns
TypeDescription
$this

getServiceAccountEmail

The email of the function's service account. If empty, defaults to {project_id}@appspot.gserviceaccount.com.

Returns
TypeDescription
string

setServiceAccountEmail

The email of the function's service account. If empty, defaults to {project_id}@appspot.gserviceaccount.com.

Parameter
NameDescription
var string
Returns
TypeDescription
$this

getUpdateTime

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

Returns
TypeDescription
Google\Protobuf\Timestamp|null

hasUpdateTime

clearUpdateTime

setUpdateTime

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

Parameter
NameDescription
var Google\Protobuf\Timestamp
Returns
TypeDescription
$this

getVersionId

Output only. The version identifier of the Cloud Function. Each deployment attempt results in a new version of a function being created.

Returns
TypeDescription
int|string

setVersionId

Output only. The version identifier of the Cloud Function. Each deployment attempt results in a new version of a function being created.

Parameter
NameDescription
var int|string
Returns
TypeDescription
$this

getLabels

Labels associated with this Cloud Function.

Returns
TypeDescription
Google\Protobuf\Internal\MapField

setLabels

Labels associated with this Cloud Function.

Parameter
NameDescription
var array|Google\Protobuf\Internal\MapField
Returns
TypeDescription
$this

getEnvironmentVariables

Environment variables that shall be available during function execution.

Returns
TypeDescription
Google\Protobuf\Internal\MapField

setEnvironmentVariables

Environment variables that shall be available during function execution.

Parameter
NameDescription
var array|Google\Protobuf\Internal\MapField
Returns
TypeDescription
$this

getBuildEnvironmentVariables

Build environment variables that shall be available during build time.

Returns
TypeDescription
Google\Protobuf\Internal\MapField

setBuildEnvironmentVariables

Build environment variables that shall be available during build time.

Parameter
NameDescription
var array|Google\Protobuf\Internal\MapField
Returns
TypeDescription
$this

getNetwork

The Serverless VPC Access connector that this cloud function can connect to. It can be either the fully qualified URI, or the short name of the connector resource. If the connector name is used, the connector must belong to the same project as the function. Otherwise, it must belong to a project within the same organization. The format of this field is either projects/{project}/global/networks/{network} or {network}, where {project} is a project id where the network is defined, and {network} is the short name of the network.

This field is mutually exclusive with vpc_connector and will be replaced by it. See the VPC documentation for more information on connecting Cloud projects.

Returns
TypeDescription
string

setNetwork

The Serverless VPC Access connector that this cloud function can connect to. It can be either the fully qualified URI, or the short name of the connector resource. If the connector name is used, the connector must belong to the same project as the function. Otherwise, it must belong to a project within the same organization. The format of this field is either projects/{project}/global/networks/{network} or {network}, where {project} is a project id where the network is defined, and {network} is the short name of the network.

This field is mutually exclusive with vpc_connector and will be replaced by it. See the VPC documentation for more information on connecting Cloud projects.

Parameter
NameDescription
var string
Returns
TypeDescription
$this

getMaxInstances

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

In some cases, such as rapid traffic surges, Cloud Functions can for a short period of time create more instances than the specified max instances limit. If your function cannot tolerate this temporary behavior, you might 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.

Returns
TypeDescription
int

setMaxInstances

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

In some cases, such as rapid traffic surges, Cloud Functions can for a short period of time create more instances than the specified max instances limit. If your function cannot tolerate this temporary behavior, you might 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.

Parameter
NameDescription
var int
Returns
TypeDescription
$this

getMinInstances

A lower bound for the number function instances that can coexist at a given time.

Returns
TypeDescription
int

setMinInstances

A lower bound for the number function instances that can coexist at a given time.

Parameter
NameDescription
var int
Returns
TypeDescription
$this

getVpcConnector

The VPC Network Connector that this cloud function can connect to. It can be either the fully qualified URI, or the short name of the network connector resource. The format of this field is projects/*/locations/*/connectors/* This field is mutually exclusive with network field and will eventually replace it.

See the VPC documentation for more information on connecting Cloud projects.

Returns
TypeDescription
string

setVpcConnector

The VPC Network Connector that this cloud function can connect to. It can be either the fully qualified URI, or the short name of the network connector resource. The format of this field is projects/*/locations/*/connectors/* This field is mutually exclusive with network field and will eventually replace it.

See the VPC documentation for more information on connecting Cloud projects.

Parameter
NameDescription
var string
Returns
TypeDescription
$this

getVpcConnectorEgressSettings

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

Returns
TypeDescription
int

setVpcConnectorEgressSettings

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

Parameter
NameDescription
var int
Returns
TypeDescription
$this

getIngressSettings

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

Returns
TypeDescription
int

setIngressSettings

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

Parameter
NameDescription
var int
Returns
TypeDescription
$this

getKmsKeyName

Resource name of a KMS crypto key (managed by the user) used to encrypt/decrypt function resources.

It must match the pattern projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}. If specified, you must also provide an artifact registry repository using the docker_repository field that was created with the same KMS crypto key. The following service accounts need to be granted the role 'Cloud KMS CryptoKey Encrypter/Decrypter (roles/cloudkms.cryptoKeyEncrypterDecrypter)' on the Key/KeyRing/Project/Organization (least access preferred).

  1. Google Cloud Functions service account (service-{project_number}@gcf-admin-robot.iam.gserviceaccount.com) - Required to protect the function's image.
  2. Google Storage service account (service-{project_number}@gs-project-accounts.iam.gserviceaccount.com) - Required to protect the function's source code. If this service account does not exist, deploying a function without a KMS key or retrieving the service agent name provisions it. For more information, see https://cloud.google.com/storage/docs/projects#service-agents and https://cloud.google.com/storage/docs/getting-service-agent#gsutil. Google Cloud Functions delegates access to service agents to protect function resources in internal projects that are not accessible by the end user.
Returns
TypeDescription
string

setKmsKeyName

Resource name of a KMS crypto key (managed by the user) used to encrypt/decrypt function resources.

It must match the pattern projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}. If specified, you must also provide an artifact registry repository using the docker_repository field that was created with the same KMS crypto key. The following service accounts need to be granted the role 'Cloud KMS CryptoKey Encrypter/Decrypter (roles/cloudkms.cryptoKeyEncrypterDecrypter)' on the Key/KeyRing/Project/Organization (least access preferred).

  1. Google Cloud Functions service account (service-{project_number}@gcf-admin-robot.iam.gserviceaccount.com) - Required to protect the function's image.
  2. Google Storage service account (service-{project_number}@gs-project-accounts.iam.gserviceaccount.com) - Required to protect the function's source code. If this service account does not exist, deploying a function without a KMS key or retrieving the service agent name provisions it. For more information, see https://cloud.google.com/storage/docs/projects#service-agents and https://cloud.google.com/storage/docs/getting-service-agent#gsutil. Google Cloud Functions delegates access to service agents to protect function resources in internal projects that are not accessible by the end user.
Parameter
NameDescription
var string
Returns
TypeDescription
$this

getBuildWorkerPool

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-<project_number>@gcf-admin-robot.iam.gserviceaccount.com) must be granted the role Cloud Build Custom Workers Builder (roles/cloudbuild.customworkers.builder) in the project.

Returns
TypeDescription
string

setBuildWorkerPool

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-<project_number>@gcf-admin-robot.iam.gserviceaccount.com) must be granted the role Cloud Build Custom Workers Builder (roles/cloudbuild.customworkers.builder) in the project.

Parameter
NameDescription
var string
Returns
TypeDescription
$this

getBuildId

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

Returns
TypeDescription
string

setBuildId

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

Parameter
NameDescription
var string
Returns
TypeDescription
$this

getBuildName

Output only. The Cloud Build Name of the function deployment.

projects/<project-number>/locations/<region>/builds/<build-id>.

Returns
TypeDescription
string

setBuildName

Output only. The Cloud Build Name of the function deployment.

projects/<project-number>/locations/<region>/builds/<build-id>.

Parameter
NameDescription
var string
Returns
TypeDescription
$this

getSecretEnvironmentVariables

Secret environment variables configuration.

Returns
TypeDescription
Google\Protobuf\Internal\RepeatedField

setSecretEnvironmentVariables

Secret environment variables configuration.

Parameter
NameDescription
var array<Google\Cloud\Functions\V1\SecretEnvVar>
Returns
TypeDescription
$this

getSecretVolumes

Secret volumes configuration.

Returns
TypeDescription
Google\Protobuf\Internal\RepeatedField

setSecretVolumes

Secret volumes configuration.

Parameter
NameDescription
var array<Google\Cloud\Functions\V1\SecretVolume>
Returns
TypeDescription
$this

getSourceToken

Input only. An identifier for Firebase function sources. Disclaimer: This field is only supported for Firebase function deployments.

Returns
TypeDescription
string

setSourceToken

Input only. An identifier for Firebase function sources. Disclaimer: This field is only supported for Firebase function deployments.

Parameter
NameDescription
var string
Returns
TypeDescription
$this

getDockerRepository

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

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'.

Returns
TypeDescription
string

setDockerRepository

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

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'.

Parameter
NameDescription
var string
Returns
TypeDescription
$this

getDockerRegistry

Docker Registry to use for this deployment.

If docker_repository field is specified, this field is automatically set as ARTIFACT_REGISTRY. If unspecified, it currently defaults to CONTAINER_REGISTRY. This field may be overridden by the backend for eligible deployments.

Returns
TypeDescription
int

setDockerRegistry

Docker Registry to use for this deployment.

If docker_repository field is specified, this field is automatically set as ARTIFACT_REGISTRY. If unspecified, it currently defaults to CONTAINER_REGISTRY. This field may be overridden by the backend for eligible deployments.

Parameter
NameDescription
var int
Returns
TypeDescription
$this

getSourceCode

Returns
TypeDescription
string

getTrigger

Returns
TypeDescription
string