My Basic Guide for setting up AWS SAM (nodejs + Lambda + API Gateway) Part 1
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).
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
b) AWS account — aws cli installation link and setup account link
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.
d.) Git — installation link
e.) Sam cli to run, build and deploy our app in AWS cloud.
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
- 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
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
- 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.
- 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
1 — is the template.yaml file
2 — is the zipped project files
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.