Create an AWS Serverless Application Model (AWS SAM) project using SAM CLI

Tomasz Łakomy
InstructorTomasz Łakomy
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 4 years ago

In this lesson we're going to learn how to create a AWS Serverless Application Model (AWS SAM) application from scratch using the SAM CLI sam init command.

In order to install the SAM CLI on your OS, follow the official AWS guide: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html

Instructor: [0:00] In order to start developing with AWS Serverless Application Model, first we need to install the Command Line Interface tools. You can find the detailed guide on the AWS documentation link, also in the description to this video.

[0:11] For instance, on Mac OS, before you get started, you have to create an AWS account, which is kind of obvious when you think about it. You have to configure IAM permissions. What that means is that your user needs to be able to create resources in your account. You have to have Docker installed, Homebrew. You have to install the CLI using the guideline provided over here.

[0:29] After running the install command from Homebrew, we have to verify the installation using SAM version command. After you verify that SAM has been successfully installed on your machine, run sam init in order to create a new project.

[0:40] A bunch of questions will follow. First up, which template source would you like to use? I'm going to go with AWS Quick Start templates because they are the most simple to use. Afterwards, I'm getting a question which runtime I would like to use.

[0:52] There's Node.js, Python, Ruby, Go, Java, .NET. Those are different versions of Node, Python, Java, and so on. Those are exactly the same languages which are supported on AWS Lambda. I'm going to go ahead with Node.js 12.

[1:04] Next up, we have to provide the project name. I'm going to call it SAM Egghead App Example. Now our application has been created. Let's go to the editor and see what we have.

[1:14] Sam init command is going to create this YAML template for us. What we can see over here, we have the description of our app. This is the sample SAM template for this app that we just created.

[1:24] Here in the resource sections, we're going to see that this app is going to build a Hello World function, which is a type of serverless function. You can find more info about the function resource under this link. It's going to use the app.lambda.handler. It's going to be executed with Node.js 12 runtime. It's going to be called by a GET request to the /hello endpoint.

[1:43] Let's take a look at our Lambda handler. Navigate to Hello World. We're going to open up the app.js file. Here's the Lambda handler which was specified in the YAML template. As we can see, it's not going to do much. Basically, whenever this function is going to be executed, there will be a response with a status code of 200 and a body of "Hello World."