Skip to content

An experimental project using Pulumi and Golang to deploy a serverless use-case to Google Cloud Platform ☁️

Notifications You must be signed in to change notification settings

Pexers/pulumi-thumbnail-generation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 

Repository files navigation

Introduction

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.

thumbnail-generation use-case

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.

Setting up the environment

  • Before deploying the use-case to Google Cloud Platform, you will first need to install:

    • Pulumi
    • gcloud - required for Pulumi to work properly.
    • Go - required for compilation.
  • 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 from FunctionEventTriggerArgs, defined in project/main.go.
    • Bucket2 was specified using the bucket2 variable, defined in project/app/main.go

Warning
Don't use the same bucket for detecting changes and storing thumbnails. If you do, the cloud function will begin to loop executions.

Pulumi deployment

  1. Inside an empty directory, run the following command to download Pulumi's serverless-gcp-go project template:
$ pulumi new serverless-gcp-go
  1. Replace main.go and app/main.go with the provided source code.
  2. Authenticate and obtain GCP credentials by executing the following command:
$ gcloud auth application-default login
  1. Run the following command to specify the path to the generated JSON credentials file:
$ pulumi config set gcp:credentials JSON_FILE_PATH
  1. Deploy the thumbnail-generation use-case using the following pulumi command:
$ pulumi up

References

About

An experimental project using Pulumi and Golang to deploy a serverless use-case to Google Cloud Platform ☁️

Topics

Resources

Stars

Watchers

Forks