Create and Deploy Your AWS SAM Application
SAM Architecture

Create and Deploy Your AWS SAM Application

Let's see How to Create and Deploy Your First Lambda Function on AWS SAM (Serverless Application Modal)

You should have your AWS account firstly and Software Requirements are Below:

  • AWS CLI
  • SAM CLI
  • Docker (optional)

To install AWS CLI in your system as per your OS you follow the official document here.

To install Serverless Application Model CLI in your system you can follow the official document here as per your operating system.

Docker is optional here, cause if you want to run your lambda locally on your system then only docker requires otherwise if you will run your Lambda in AWS console itself then Docker not required at all. for installing docker in your local machine you can follow the official document here.

Architecture for Your First Lambda

Note: When we are taking about Serverless Architecture with Lambda so we have two ways first Serverless.com from in which we can deploy our lambda and second is AWS SAM in which via using AWS Lambda service of AWS we can deploy our lambda. Here we are mainly discussing about AWS SAM only.


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 asks for project name, by default sam-app was given you can change it also.

Now Your Application Code Base Created Successfully

  • 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.        

Congrats, now your Lambda is ready to deploy in your AWS account :)

Firstly now you have to configure your AWS CLI.

~ $ aws configure        

  1. Enter your access key.
  2. Enter your secret key.
  3. Enter your AWS region.
  4. Format: you can use JSON.

~ $ sam deploy --guided         

#This above command 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 CLI Commands with Description:

~ $ 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
        

AWS CLI Commands with Description:

~ $ 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 .......        

Happy Coding </>

Follow me for more informative content like this :)

要查看或添加评论,请登录

Sanjay Kumar ????的更多文章

  • Node.js, RabbitMQ and Docker Realtime App

    Node.js, RabbitMQ and Docker Realtime App

    Let's directly jump into how you can make your first RabbitMQ (Popular Message Broker) application in node.js.

  • JavaScript Output Based Interview Questions

    JavaScript Output Based Interview Questions

    You mostly seen in JavaScript Interviews there interviewers must asks output based questions in which candidate stuck…

  • JavaScript Most Commonly Asked Data Structure Questions

    JavaScript Most Commonly Asked Data Structure Questions

    In this article we cover some of the most commonly asked JavaScript data structure questions related to arrays, strings…

    2 条评论
  • Let's See Top 10 React JS Interview Questions

    Let's See Top 10 React JS Interview Questions

    ReactJS is an open-source, component-based front end library responsible only for the view layer of the application. It…

  • Let's Understand Some JavaScript Importance

    Let's Understand Some JavaScript Importance

    If we talk about JavaScript in 2023, it is the most popular programming language as more then 90 % of websites in the…

    1 条评论
  • Top 10 Junior PHP Developer Interview Questions

    Top 10 Junior PHP Developer Interview Questions

    Are you preparing for your Junior PHP Developer Interview if Yes so this article is for you. PHP is a general-purpose…

  • Some of the Best IT companies in Noida

    Some of the Best IT companies in Noida

    Hello Everyone, In this video you will get the information about best it companies in Noida and it is really helpful…

    6 条评论
  • Become ‘Artist’ Is My Passion

    Become ‘Artist’ Is My Passion

    I don’t know from where I was started my career and where I am write now. I think right now I am just finding stability…

  • Dance Choreo India (DCI)

    Dance Choreo India (DCI)

    Dance Choreo India (DCI) is started and founded by 'Sanjay Kumar' in july 2018 with his friend 'Aakash Rastogi' who was…

  • Education Funda

    Education Funda

    Hello Everyone, "Education Funda" is a YouTube channel of mine. In this channel you 'll get videos related to…

社区洞察

其他会员也浏览了