My Basic Guide for setting up AWS SAM (nodejs + Lambda + API Gateway) Part 1

June Ligan
5 min readJun 9, 2022

My goal with this rough documentation is to help my future self and those newbies out there like me that who wants to try out new things, especially this trending Serverless lightweight API in AWS using dynamodb(nosql).

Photo by Pixabay from Pexels

End of this doc: We should have created a simple AWS SAM and figuring out those errors along the way.

Disclaimer: I'm not certified, I'm a newbie, though I have an experience before but I'm already rusty with AWS features, promise, no joke! 😅

1.)Install software dependencies
Here’s the link for the steps of the required dependencies installation
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-windows.html

In summary: We need, nodejs, aws cli, docker, sam cli

a) Node Package Manager (npm)
— Nodejs is for our sample lambda function in javascript

Nodejs is for our lambda function

b) AWS account — aws cli installation link and setup account link

install aws cli
login to AWS then go to IAM (use search bar)
use the above values to your “aws configure”
Aws cli to configure your dev account locally to be used for our sam app

c.) Docker is needed since the local sam app will run at docker. We'll also include here on how to run your local app in fast pace, like skipping those docker stuff.

windows desktop docker

d.) Git — installation link

to easily downloads the sample “sam init” files

e.) Sam cli to run, build and deploy our app in AWS cloud.

64 bit installer

2.) Create basic sam app
- run “sam init”, let’s just use the quick start template and hello world example

3.) Files to take note

The project files
  • app.js — contains the lambda function
  • template.yaml — contains the AWS cloudformation for your lambda function, API gateway and Tables if necessary
  • events.json — is the request schema which is one of the parameters of the lambda function app.js
  • test-handler.js — unit test for your app.js lambda function
  • package.json — contains our app’s dependencies and other script functions

4.) Build — run “sam build -t template.yaml”
this will create the “.aws-sam” directory for the built files

The highlighted HelloWorldFunction is the Resource name in our template.yaml

5.) Deploy — run “sam deploy -t template.yaml --guided”
This will deploy the app given the template.yaml with cli guidance or step by step procedure

  1. samconfig.toml file will be checked every time we will deploy our aws-sam app, ATM, we will be given a set of questions along the way and set their values which will be used as config for our future deployment.
  2. the stack name of your app and will appear to your AWS cloudformation

3. the region you want to deploy your app — can’t explain thoroughly coz I can’t 😅

4. Confirmation config — this will ask you first given the prepared changeset resources before deploying it in AWS

5. We are allowing the changeset to be deployed in AWS

The above outputs are based from our template.yaml

6. We will not yet disable the rollback since we will be having a lot of changes ahead.

7. Honestly, haven’t tried it yet to include the authorization 😅maybe in the future haha but we’ll just answer YES atm.

8. This will save our config values to a file by entering Y.

9. We can enter a file name but the default name is “samconfig.toml”. you can just press enter if you want to use the default name

10. the environment for your config values

s3_bucket is where your files been uploaded

AWS S3 Bucket

1 — is the template.yaml file
2 — is the zipped project files

The 2nd file in the s3 bucket (NOTE the folder name)

let’s continue to the next part of this doc 😆

can’t upload images, not really sure what happened, but I’m blocked but I just want to share my thoughts and to help my future self 😆

For somebody out there, hope this helps, but if you want to continue, you can proceed to the 2nd part.

Please let me know if you have something in mind, comments or questions.

--

--