Serverless Deployment with AWS SAM
Easy serverless architecture deployment steps
What is Serverless?
In simple words, It means running your application without having to manage or interact with the servers that your application runs on top. There are several serverless frameworks out there but my favourite is AWS SAM. In this article, I demonstrated how to deploy serverless application. You can use this concept to start deploying serverless applications.
What is AWS SAM ?
AWS Serverless Application Model (AWS SAM) is an open-source framework that you can use to build serverless applications on AWS.
You can use AWS SAM CLI to build serverless applications that are defined by AWS SAM templates. The CLI provides commands that enable you to verify that AWS SAM template files are written according to the specification, invoke Lambda functions locally, step-through debug Lambda functions, package and deploy serverless applications to the AWS Cloud.
What you need?
Lambda template file, application code and S3 bucket.
Template file: lambda.yml
Sample application code: index.js
exports.handler = (event, context, callback) => {// TODO implementconst response = {statusCode: 200,body: JSON.stringify('Happy!, Your Lambda Function deployed using SAM!')};callback(null, response);};
Getting Started
- Pre-requisties: After installing Python 3.x, install pip and the SAM CLI:
easy_install pip
pip install aws-sam-cli
2) Create an S3bucket:
aws s3 mb s3://codebucket — region eu-west-2 #choose your own bucket name and region
3) Package your deployment:
sam package \
— template-file ./lambda.yml \
— output-template-file sam-template.yml \
— s3-bucket codebucket
Note: Remember to use the bucket name you used in the previous step
4) Deploy your package:
sam deploy \
— template-file sam-template.yml \
— stack-name sampleserverlessappstack \
— capabilities CAPABILITY_IAM
Check AWS Lambda web console to test your new function.
Congratulations!!! Go Serverless!!!