SAM
Serverless Application Model: extension of CloudFormation
Last updated
Serverless Application Model: extension of CloudFormation
Last updated
Docs |
A tool kit for building and running serverless applications, contains 2 parts:
Can use for deploy serverless application: run locally, package, or deploy to the cloud.
Benefits:
Construct serverless applications in fewer lines of code.
The development time is significantly reduced.
SAM will translate this CloudFormation syntax to CloudFormation stack that create Lambda and API Gateway, Dynamo table.
SAM template has Transform: ‘AWS::Serverless-2016–10–31’
line in the template.
SAM resources can be written alongside the native CloudFormation resources. You can also use intrinsic functions and pseudo parameters in a SAM template just like you would in a native CloudFormation template.
sam init
: initialize the project
sam package
: packages your AWS SAM application source code, dependencies and resources into a deployment package (.zip file). The .zip file is then uploaded to the S3 bucket that you specify. After that, it returns a copy of your AWS SAM template, replacing references to local artifacts with the Amazon S3 location where the artifacts are uploaded.
sam build
: build app to .aws-sam
directory.
sam deploy
: will call sam package
internally, so don't need to call it seperately.
Here, we use the sam deploy --guided command to deploy our application through an interactive flow. The AWS SAM CLI guides us through configuring our application's deployment settings, transforms our template into AWS CloudFormation, and deploys to AWS CloudFormation to create our resources.
sam pipeline init --bootstrap
: to configure a CI/CD deployment pipeline for our application.
cdk synth
: it reads your CDK app code and generates an CloudFormation template.
SAM is built-in with CodeDeploy to help ensure safe Lambda deployments.
sam local invoke
: perform local debugging and test.
sam local start-api
: starts a local instance of API Gateway to test HTTP endpoints.
sam remote invoke
: to test a deployed Lambda function in the cloud.
sam list
: to view our deployed resources.
sam logs
: to view our functions' logs.
sam sync --watch
: to have the AWS SAM CLI watch for local changes. This command is typically used for quick syncing of local changes to AWS and is more suitable for rapid development testing.
SAM template has Transform: ‘AWS::Serverless-2016–10–31’
line in the template.