
AWS SAM
The AWS Serverless Application Model (SAM) is an open-source framework for building serverless applications.
It provides shorthand syntax to express functions, APIs, databases, and event source mappings.
During deployment, SAM transforms and expands the SAM syntax into AWS CloudFormation syntax, enabling you to build serverless applications faster.
AWS SAM template specification - Define your serverless application.
AWS SAM command line interface (AWS SAM CLI) - SAM CLI provides a Lambda-like execution environment that lets you locally build, test, and debug applications defined by SAM templates.
What is an AWS CloudFormation Template?
A template is a declaration of the AWS resources that make up a stack.
The template is stored as a text file in the JavaScript Object Notation (JSON) or YAML standard format.
The only required top-level object is the Resources object, which must declare at least one resource.
Packaging Serverless Applications - You can deploy your application by using AWS SAM command line interface (CLI) commands.
# Package SAM template
$ sam package --template-file sam.yaml --s3-bucket mybucket --output-template-file packaged.yaml
Deploying Serverless Applications
# Deploy packaged SAM template
$ sam deploy --template-file ./packaged.yaml --stack-name mystack --capabilities CAPABILITY_IAM
Benefits of Using AWS SAM
Single-deployment configuration. AWS SAM makes it easy to organize related components and resources and operate on a single stack.
Extension of AWS CloudFormation. AWS SAM is an extension of AWS CloudFormation, you get the reliable deployment capabilities of AWS CloudFormation.
Built-in best practices. You can use AWS SAM to define and deploy your infrastructure as config.
Local debugging and testing. The AWS SAM CLI lets you locally build, test, and debug serverless applications that are defined by AWS SAM templates.
Deploying a Hello World Application - Prerequisites
1. Created an AWS account and Configure IAM permissions.
2. Install the AWS CLI, Docker, Homebrew, AWS SAM CLI and Python.
#Make sure that the Region for this bucket aligns with where you deploy
aws s3 mb s3://bucketname --region region # Example regions: us-east-1
#Step 1 - Download a sample application
sam init --runtime python3.7
#Step 2 - Build your application
cd sam-app sam build
#Step 3 - Package your application
sam package --output-template packaged.yaml --s3-bucket bucketname
#Step 4 - Deploy your application
sam deploy --template-file packaged.yaml --region us-west-2 --capabilities CAPABILITY_IAM --stack-name aws-sam-getting-started
The AWS Serverless Application Model (SAM) is an open-source framework for building serverless applications. It provides shorthand syntax to express functions, APIs, databases, and event source mappings. With just a few lines per resource, you can define the application you want and model it using YAML. During deployment, SAM transforms and expands the SAM syntax into AWS CloudFormation syntax, enabling you to build serverless applications faster.
Why SAM
Single-deployment configuration. SAM makes it easy to organize related components and resources, and operate on a single stack. You can use SAM to share configuration (such as memory and timeouts) between resources, and deploy all related resources together as a single, versioned entity.
Local debugging and testing. Use SAM CLI to locally build, test, and debug SAM applications on a Lambda-like execution environment. It tightens the development loop by helping you find & troubleshoot issues locally that you might otherwise identify only after deploying to the cloud.
Deep integration with development tools. You can use SAM with a suite of tools you love and use.
IDEs: PyCharm, IntelliJ, Visual Studio Code, Visual Studio, AWS Cloud9
Build: CodeBuild
Deploy: CodeDeploy, Jenkins
Continuous Delivery Pipelines: CodePipeline
Discover Serverless Apps & Patterns: AWS Serverless Application Repository
Built-in best practices. You can use SAM to define and deploy your infrastructure as configuration. This makes it possible for you to use and enforce best practices through code reviews. Also, with a few lines of configuration, you can enable safe deployments through CodeDeploy, and can enable tracing using AWS X-Ray.
Extension of AWS CloudFormation. Because SAM is an extension of AWS CloudFormation, you get the reliable deployment capabilities of AWS CloudFormation. You can define resources by using CloudFormation in your SAM template. Also, you can use the full suite of resources, intrinsic functions, and other template features that are available in CloudFormation.
Using AWS SAM for serverless application development saves a lot of time by eliminating much of the boilerplate that CFN templates require. It extends CFN with new resource types that follow AWS best practices and are more comfortable to use. The SAM CLI also generates code based on templates that are available online.
A serverless application might use DynamoDB tables, S3 object storage, and Amazon API Gateway resources as components. The key benefit that AWS SAM provides is a new simplified syntax to describe the components being used. This template can be either a YAML or JSON file. CloudFormation files can be long and complex, so AWS invented AWS SAM. AWS SAM is an extension of CloudFormation that simplifies the development of serverless applications.
#serverless #serverless architecture #serverless computing #cloud functions #aws lambda #serverless framework #aws serverless #serverless application #aws serverless architecture #serverless lambda #aws lambda nodejs #server less architecture #aws lambda #serverless functions #serverless examples #serverless npm