A project where I built and deployed a serverless API using Google Cloud Functions and Firestore, integrated with Cloud Build as CI/CD to deploy functions on every push to GitHub automatically. An API that can serve resume data in JSON format. I used Terraform to manage and provision cloud infrastructure.
Reference website: https://www.cloudresumeapi.dev
Pre-requisites
- A Google Cloud Platform account and a project
- The Terraform CLI
- The text editor I used is Visual Studio Code
- A project and service account in GCP
- A GitHub repository
- A Firestore database - set up a table named
Resumes
containing sample resume data
Use this schema to create your own JSON resume.
Create the infrastructure using Terraform
provider.tf
variables.tf
terraform.tfvars
main.tf
Google Cloud Functions: Fetch and return resume data based on an id. Utilize HTTP Trigger with anonymous access.
main.py
requirements.txt
(define the dependencies - these will be installed when the function is deployed)
In the main.py
you have to import Flask
- used for web development, including the jsnoify method used in the script and google-cloud-firestore
- used to interact with Firestore
functions-framework=3.*
-The functions-framework is a set of libraries for writing lightweight, portable Python functions that can run in various environments, including Google Cloud Functions, your local development machine, or other cloud environments. It provides a consistent execution environment and request context, and allows you to focus on writing your function logic rather than worrying about the infrastructure.
Once you have configured the project, you can upload the Terraform configuration to Google Cloud Platform by running the following command:
terraform plan
To check the changes that will be made to your infrastructure.
terraform apply
When prompted, review the changes and type yes
to confirm that you want to apply the changes.
- I authorized Cloud Build to access the GitHub repository
- I created a trigger to build the function when a new commit is pushed to the repository
- I created the cloudbuild.yaml file to define the build steps
API URL: https://europe-west2-cloud-resume-api-418008.cloudfunctions.net/cloudresumeapi-1 Or open the terminal and run the following command:
curl https://europe-west2-cloud-resume-api-418008.cloudfunctions.net/cloudresumeapi-1