A developer's guide to building serverless apps on the cloud

In this series, I’ll discuss a few topics crucial to building serverless applications while using Google Cloud. These topics will span across deployment, CI/CD, tooling, backend-as-a-service, and more.

In this article, I will discuss how developers at DevShopZ easily moved from local development to the Cloud. This covers simple functions, web-based applications, and containerized applications including code samples.

If you are new to Serverless, check out this post

DevShopZ recently started a new project for a client; their engineers have made lots of progress in building the project, but the project manager wants it deployed so that the client can have an idea of what he’s getting and provide feedback to the team.

Developers at DevShopZ started the project by building simple API endpoints​ and then moved to integrating the frontend and other tools (e.g., such as Docker). We shall see how the deployment was done at each stage of the project.

Before you begin:

  • The developers made use of the Google Cloud account for free. Click here for details.
  • They created a new GCP project, you can do the same here.
  • The developers used the Google Cloud Shell terminal to execute the deployment commands.

Deploying Functions

The engineers built the first simple endpoint which is a Python function that returns a JSON message. Tip: You could use any language of choice.

The endpoint function was deployed to Cloud Functions.

Google Cloud Functions is a lightweight compute solution for developers to create single-purpose, stand-alone functions that respond to cloud events without the need to manage a server or runtime environment.

gcloud functions deploy hello_world --runtime python37 --trigger-http

Execute the command above on Cloud Shell after cloning the sample codes from the Gist or setting up your own codes.

Screenshot from 2020-01-09 00-59-14.png Deployed Function

Deploying Web Applications (without containers)

The project has grown into a full Web Application, built using the Flask Web framework, and now includes static files. Tip: You can use any framework of choice.

The Web Application was deployed to App Engine.

App Engine is a fully managed, serverless platform for developing and hosting web applications at scale. You can choose from several popular languages, libraries, and frameworks to develop your apps. Then, let App Engine take care of provisioning servers and scaling your app instances based on demand.

gcloud app deploy

Execute the command above on Cloud Shell after cloning the sample codes from the Gist or setting up your own codes.

Screenshot from 2020-01-09 00-51-57.png Deployed Web Application

Deploying containers

The team decided to adopt containerization technologies by Dockerizing the existing Web Application. The source codes were updated to include a Dockerfile, which was used to build the container image.

There are multiple options for deploying container images on Google Cloud, see this short video.

Cloud Run is a managed compute platform that automatically deploys and scales your stateless containers. Cloud Run is serverless, i.e., it abstracts away all infrastructure management so you can focus on what matters most — building great applications.

gcloud builds submit --config cloudbuild.yaml

The cloudbuild.yaml file is a configuration file for Google Cloud Build that contains two steps:

  1. Builds the container image & uploads it to the Google Container Registry

  2. Deploys the image to Cloud Run.

Execute the command above on Cloud Shell after cloning the sample codes from the Gist or setting up your own codes

Screenshot from 2020-01-09 01-38-21.png Deployed Containerized Web App

Useful Links

Stay tuned for the next article where I will discuss a more exciting serverless topic.

Free Resources