Create and Deploy AWS SAM Application
How To Create and Deploy Your First Lambda Function on AWS Serverless Application Modal
AWS SAM - Education Funda |
Create Your SAM Application
Software Requirements:
- AWS CLI (Reference Link)
- SAM CLI (Reference Link)
- Docker (Reference Link)
AWS Serverless Architecture - Education Funda |
Now All Will Happen With Command Line Interface
Now open Terminal and Go to your directory in which you want to create your project.
$ sam init #hit enter this command
~ This will appear 2 option, 1 AWS Quick Start and 2 Custom Template
For making things simple you can 1 at moment.
~ Now you need to select template, at moment you can select Hello World Example.
~ Now it will ask for programming language Python by default and you can select other as well such as Node.js, Java, etc.
~ Now you can choose ZIP option.
~ Now it will ask starter template, you can select anyone from that Hello World Example.
~ X-Ray tracing you can enable so select Y.
~ Enable Cloud Watch now with select Y.
~ Now it ask for project name, by default sam-app was given you can change it also.
Now Your Application Code Base Created
- You can check your template.yaml file now, description is given in that.
- samconfig.toml for your deployment purpose, it will use.
Now Make Build of Your SAM Application
Now go to your project directory with
~ $ cd directory-name
~ $ sam build #this command will generate build source code
~ $ sam validate #to check your template
~ $ sam local invoke #to run your lambda function in local, this will run with Docker
Now Deploy Your SAM Lambda Application in AWS
Firstly now you have to configure your AWS CLI.
~ $ aws configure
Enter your access key
Enter your secret key
Enter your AWS region
Format: you can use JSON.
~ $ sam deploy --guided #this will deploy your code on AWS S3, Lambda, API Gateway and Cloud Formation.
That's it, You have successfully deployed your SAM Lambda Application in AWS 😉
Helpful Commands:
~ $ aws configure #......... default .........
~ $ aws configure --profile new-profile-name #........ configure with profile name .............
~ $ aws configure list-profiles #........ get list of all configured profiles
~ $ export AWS_PROFILE=new-profile-name #........ select specific profile
~ $ aws sts get-caller-identity #....... show the credentials if configured .....
~ $ aws cloudformation delete-stack --stack-name app-name --profile profile-name #.... delete whole application from backend cloud ... Reference
~ $ sam deploy --guided #....... deploy with default configuration ..........
~ $ sam deploy --profile profile-name --guided #........ deploy with specific profile name .......
~ $ sam local start-api #...... we can run apis locally ........
~ $ sam local invoke -e events/event.json #..... invoke application with event parameters ......
~ $ sam local invoke "SpecificFunctionName" -e events/event.json # ........ invoke locally specific lambda function .......
Follow me in LinkedIn.
Happy Coding !!
Comments
Post a Comment