Lab 1 - Basics

In this lab we will create our first Serverless application and explore it.

Bootstrap serverless app

First we bootstrap the Serverless “Hello World” example. Change directories into your $GOPATH and create the usual Go boilerplate.

mkdir -p $GOPATH/src/<YOUR_NAME>

Now generate your template.

serverless create -t aws-go-dep -p godays-workshop

This will create an example app with the relevant configuration files and directory structure.

Build and deploy

Since Lambda requires us to provide the compiled binary, we have to build it beforehand.

make build

This compiles the functions hello and world and places the binaries in the bin/ subdirectory.

To deploy the functions and create the AWS components (Lambda function, API Gateway, DNS Entries) we run:

make deploy

This will run serverless deploy to deploy our functions.

Pay attention to the log output. Especially lines prefixed with CloudFormation - …. To take a look under the hood look into the .serverless folder. You’ll see two JSON files. This is the Cloudformation stack for your application.

Run the functions

To run the function we can use either the HTTP endpoint (via API Gateway) or use the Serverless tool to invoke the function directly. Try it out. Figure out the URL to your service by taking a look at the shell output from the command you ran above.

Need help?

Do you notice any differences when running the function via curl or when you invoke it directly?