AWS SAM CLI Getting started guide

AWS SAM CLI (Serverless Application Model Command Line Interface) is an open-source command-line tool that makes it easy to build, test, and deploy serverless applications on AWS. It provides a set of commands to package and deploy serverless applications, and also includes a local development environment for testing your applications locally before deploying them to AWS.

The AWS Serverless Application Model (SAM) CLI is an open-source CLI tool that helps you develop serverless applications containing Lambda functions, Step Functions, API Gateway, EventBridge, SQS, SNS and more.

The SAM CLI uses AWS CloudFormation to define the infrastructure and resources required by your serverless application, and then deploys and manages those resources on your behalf. It supports a variety of programming languages and frameworks, including Node.js, Python, Java, and .NET Core, among others. The SAM CLI can be used as a standalone tool or in conjunction with other AWS services and tools, such as the AWS CLI and AWS CloudFormation Designer.

Some of the features it provides are:

  • Initialize serverless applications in minutes with AWS-provided infrastructure templates with sam init
  • Compile, build, and package Lambda functions with provided runtimes and with custom Makefile workflows, for zip and image types of Lambda functions with sam build
  • Locally test a Lambda function and API Gateway easily in a Docker container with sam local commands on SAM and CDK applications
  • Sync and test your changes in the cloud with sam sync in your developer environments
  • Deploy your SAM and CloudFormation templates using sam deploy
  • Quickly create pipelines with prebuilt templates with popular CI/CD systems using sam pipeline init
  • Tail CloudWatch logs and X-Ray traces with sam logs and sam traces

SAM workflow

How to install AWS SAM in linux?

  1. Download the AWS SAM CLI .zip file to a directory of your choice.
  2. Verify the integrity and authenticity of the downloaded installer files by generating a hash value using the following command:$ sha256sum aws-sam-cli-linux-x86_64.zipThe output should look like the following example: <64-character SHA256 hash value> aws-sam-cli-linux-x86_64.zipCompare the 64-character SHA-256 hash value with the one for your desired AWS SAM CLI version in the AWS SAM CLI release notes on GitHub.
  3. Unzip the installation files into a directory of your choice. The following is an example, using the sam-installation subdirectory.NoteIf your operating system doesn’t have the built-in unzip command, use an equivalent.$ unzip aws-sam-cli-linux-x86_64.zip -d sam-installation
  4. Install the AWS SAM CLI by running the install executable. This executable is located in the directory used in the previous step. The following is an example, using the sam-installation subdirectory:$ sudo ./sam-installation/install
  5. Verify the installation.$ sam --versionOn successful installation, you should see output like the following: SAM CLI, version 1.58.0

Initialize a new project

Build your application for deployment

Perform local debugging and testing

Deploy your application

Reference

Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x