Serverless Framework is a solution to build, test, and deploy functions from a local environment to any of the major cloud providers such as AWS, Azure, or Google Cloud....

7 months ago

Latest Post Kubernetes Cheat Sheet by Tyler Moon

While there has been an explosion of serverless computing providers, tools, and documentation recently, there is a disconnect between writing code locally, in a typical software development fashion, and writing code in cloud portals. This is where the Serverless Framework project comes in with a solution to build, test, and deploy functions from a local environment to any of the major cloud providers such as AWS, Azure, or Google Cloud. In this article, we will look into how to use this framework to deploy a simple hello world function to a cloud provider.t

Prerequisites

Install

The Serverless Framework is installed as a global NPM package. Run the following NPM command to install it:

npm install -g serverless

It is as easy as that! Now try running serverless help to make sure it installed correctly.

Note: If you have permission issues with global NPM packages check out this article on how to fix it

Create a Project

The commands listed below will create a new directory and then build the skeleton hello world project inside of it.

mkdir quickstart
serverless create --template aws-nodejs --path quickstart

Deployment Time

Change directory to the quickstart directory created above and execute:

serverless deploy -v
serverless invoke -f hello -l

This will deploy the function code in handler.js by using the configuration stored in serverless.yml and the AWS CloudFormation setup in this example. If you were targeting Azure or Google Cloud it would use their cloud templating systems but the serverless commands would be the same. The second command there will invoke the hello function and stream back the logs. And that is all it takes to deploy and execute functions!

Cleanup

For many cloud systems, and especially AWS, it can be difficult to keep track of created resources and delete them after you are done with them. This is especially important when doing getting started tutorials as you almost never want to keep them laying around after finishing the tutorial. The Serverless Framework provides an easy serverless remove command that will remove all the resources associated with the current project.

Summary

In this short article, we saw how to set up an AWS Lambda serverless project using the Serverless Framework. This framework allows for local development and versioning of serverless applications and is cloud provider agnostic. We will explore more of this framework in the future.

Tyler Moon

Published 7 months ago

Comments?

Leave us your opinion.