{"id":33597,"date":"2023-04-27T13:55:02","date_gmt":"2023-04-27T13:55:02","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=33597"},"modified":"2023-04-27T13:59:37","modified_gmt":"2023-04-27T13:59:37","slug":"aws-sam-cli-getting-started-guide","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/aws-sam-cli-getting-started-guide\/","title":{"rendered":"AWS SAM CLI Getting started guide"},"content":{"rendered":"\n<p>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. <\/p>\n\n\n\n<p>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. <\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Some of the features it provides are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Initialize serverless applications<\/strong>&nbsp;in minutes with AWS-provided infrastructure templates with&nbsp;<code>sam init<\/code><\/li>\n\n\n\n<li><strong>Compile, build, and package<\/strong>&nbsp;Lambda functions with provided runtimes and with custom Makefile workflows, for zip and image types of Lambda functions with&nbsp;<code>sam build<\/code><\/li>\n\n\n\n<li><strong>Locally test<\/strong>&nbsp;a Lambda function and API Gateway easily in a Docker container with&nbsp;<code>sam local<\/code>&nbsp;commands on SAM and CDK applications<\/li>\n\n\n\n<li><strong>Sync and test your changes in the cloud<\/strong>&nbsp;with&nbsp;<code>sam sync<\/code>&nbsp;in your developer environments<\/li>\n\n\n\n<li><strong>Deploy<\/strong>&nbsp;your SAM and CloudFormation templates using&nbsp;<code>sam deploy<\/code><\/li>\n\n\n\n<li>Quickly&nbsp;<strong>create pipelines<\/strong>&nbsp;with prebuilt templates with popular CI\/CD systems using&nbsp;<code>sam pipeline init<\/code><\/li>\n\n\n\n<li><strong>Tail CloudWatch logs and X-Ray traces<\/strong>&nbsp;with&nbsp;<code>sam logs<\/code>&nbsp;and&nbsp;<code>sam traces<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">SAM workflow<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"495\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2023\/04\/image-129-1024x495.png\" alt=\"\" class=\"wp-image-33599\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2023\/04\/image-129-1024x495.png 1024w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2023\/04\/image-129-300x145.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2023\/04\/image-129-768x371.png 768w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2023\/04\/image-129.png 1400w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">How to install AWS SAM in linux?<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Download the&nbsp;<a href=\"https:\/\/github.com\/aws\/aws-sam-cli\/releases\/latest\/download\/aws-sam-cli-linux-x86_64.zip\" rel=\"noreferrer noopener\" target=\"_blank\">AWS SAM CLI .zip file<\/a>&nbsp;to a directory of your choice.<\/li>\n\n\n\n<li>Verify the integrity and authenticity of the downloaded installer files by generating a hash value using the following command:<code>$ sha256sum aws-sam-cli-linux-x86_64.zip<\/code>The output should look like the following example: &lt;64-character SHA256 hash value&gt; 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&nbsp;<a href=\"https:\/\/github.com\/aws\/aws-sam-cli\/releases\/latest\" rel=\"noreferrer noopener\" target=\"_blank\">AWS SAM CLI release notes<\/a>&nbsp;on GitHub.<\/li>\n\n\n\n<li>Unzip the installation files into a directory of your choice. The following is an example, using the&nbsp;<code>sam-installation<\/code>&nbsp;subdirectory.<strong><\/strong>NoteIf your operating system doesn&#8217;t have the built-in&nbsp;<strong>unzip<\/strong>&nbsp;command, use an equivalent.<code>$ unzip aws-sam-cli-linux-x86_64.zip -d sam-installation<\/code><\/li>\n\n\n\n<li>Install the AWS SAM CLI by running the&nbsp;<code>install<\/code>&nbsp;executable. This executable is located in the directory used in the previous step. The following is an example, using the&nbsp;<code>sam-installation<\/code>&nbsp;subdirectory:<code>$ sudo .\/sam-installation\/install<\/code><\/li>\n\n\n\n<li>Verify the installation.<code>$ sam --version<\/code>On successful installation, you should see output like the following: SAM CLI, version 1.58.0<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Initialize a new project<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/docs.aws.amazon.com\/images\/serverless-application-model\/latest\/developerguide\/images\/what-is-sam-01.gif\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Build your application for deployment<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/docs.aws.amazon.com\/images\/serverless-application-model\/latest\/developerguide\/images\/what-is-sam-02.gif\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Perform local debugging and testing<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/docs.aws.amazon.com\/images\/serverless-application-model\/latest\/developerguide\/images\/what-is-sam-04.gif\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Deploy your application<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/docs.aws.amazon.com\/images\/serverless-application-model\/latest\/developerguide\/images\/what-is-sam-03.gif\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Reference<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/aws.amazon.com\/serverless\/sam\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/aws.amazon.com\/serverless\/sam\/<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/aws\/aws-sam-cli\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/aws\/aws-sam-cli<\/a><\/li>\n\n\n\n<li><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-33597","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/33597","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=33597"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/33597\/revisions"}],"predecessor-version":[{"id":33602,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/33597\/revisions\/33602"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=33597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=33597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=33597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}