Serverless Application Model (SAM)
Introduction to SAM
- Serverless Application Model (SAM) is an extention to CloudFormation used to define serverless applications
- Simplified syntax for defining serverless resources: APIs, Lambda Functions, DynamoDB Tables etc
- Use the SAM CLI to package your deployment code, upload it to S3 and deploy your serverless application
SAM CLI Commands
- Takes yaml template as input
- Outputs sam template
- stores in s3 bucket
sam package\
--template-file ./mytemplate.yml \
--output-template-file sam-template.yaml \
--s3-bucket s3-bucket-name
- Takes as input sam template created previously
- specifies cloud formation stack (mystack)
- capabilities that lets cloudformation create an IAM role to allow the function to execute
sam deploy\
--template-file sam-template.yml\
--stack-name mystack\
--capabilities CAPABILITY_IAM
CloudFormation & SAM Exam Tips
- SAM is the Serverless Application Model
- Allows you to define and provision serverless applications using CloudFormation
- Uses the SAM CLI commands to package and deploy:
- sam package
- packages your application and uploads to S3
- sam deploy
- deploys your serverless app using CloudFormation
- sam package
SAM Transform
For serverless applications (also referred to as Lambda-Based applications), the Transform section specifies the version of the AWS Serverless Application Model to use. When you specify a transform, you can use AWS SAM syntax to declare resources in your template. The model defines the syntax that you can use and how it is processed. More specificaly, the AWS::Serverless transform, which is a macro hosted by AWS CloudFormation, taskes an entire template written in the AWS SAM syntax and transforms and expands it into a compliant AWS CloudFormation template.
Extras
- "AWS::Serverless::UserPool" : UserPool applies to the Cognito service which is used for authentication for mobile app and web. There is no resource named UserPool in the Serverless Application Model.
- The AWS::Serverless transform is specifically used for transforming an entire template written in the AWS Serverless Application Model (AWS SAM) syntax into a compliant AWS CloudFormation template.
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-aws-serverless.html