An experimental project using Pulumi and Golang to deploy a serverless use-case to Google Cloud Platform (GCP). Pulumi is a modern infrastructure as code (IaC) platform that allows developers to use familiar programming languages and tools to build, deploy, and manage cloud infrastructure.
The deployed function implements the use-case described below.
The use case starts with the upload of an image file to be persisted in a storage bucket (Bucket1). The upload action triggers the execution of a cloud function responsible for generating and storing a new image thumbnail in a second storage bucket (Bucket2). Prior to the thumbnail generation, the function makes a remote call to the provider's storage service to read the bytes of the uploaded image that triggered its execution. The thumbnail generation operation simply consists in cutting the image width in half using the image package from Golang.
-
Before deploying the use-case to Google Cloud Platform, you will first need to install:
-
The use-case also requires the creation of two buckets (Bucket1 & Bucket2). Bucket1 detects changes and triggers function executions. Bucket2 simply stores new thumbnails.
- Bucket1 was configured using the
Resource
property fromFunctionEventTriggerArgs
, defined in project/main.go. - Bucket2 was specified using the
bucket2
variable, defined in project/app/main.go
- Bucket1 was configured using the
Warning
Don't use the same bucket for detecting changes and storing thumbnails. If you do, the cloud function will begin to loop executions.
- Inside an empty directory, run the following command to download Pulumi's serverless-gcp-go project template:
$ pulumi new serverless-gcp-go
- Replace main.go and app/main.go with the provided source code.
- Authenticate and obtain GCP credentials by executing the following command:
$ gcloud auth application-default login
- Run the following command to specify the path to the generated JSON credentials file:
$ pulumi config set gcp:credentials JSON_FILE_PATH
- Deploy the thumbnail-generation use-case using the following pulumi command:
$ pulumi up