Serverless Application Model (SAM) and AWS Lambda
Instruction: Explain the AWS Serverless Application Model (SAM) and how it facilitates working with AWS Lambda.
Updated
Official answer
AWS SAM provides a CloudFormation extension for declaring serverless resources and a CLI for building, testing and deploying them. The template can describe a function, its event sources, permissions and related resources; the SAM transform expands its shorthand into CloudFormation resources.
A practical workflow is to version the template and code, validate the template, build the package for the target runtime/architecture, run unit and local event tests, and deploy a reviewed change set to a test environment. SAM templates can also contain ordinary CloudFormation resources; a complex application does not automatically require abandoning SAM.
Local SAM execution can exercise handler behavior and supported API emulation. It does not prove deployed IAM policies, VPC routes, event delivery or service quotas. Test those with authorized integration tests in an isolated AWS environment. Keep test credentials and real customer payloads out of local fixtures.
Review generated permissions, artifact provenance, environment parameters and changes to persistent resources before deployment. SAM can configure versions, aliases and CodeDeploy gradual traffic shifting with alarms. Rolling a function alias back does not reverse a database migration or an external side effect, so compatibility and recovery need separate plans.
The benefit is repeatable infrastructure and development workflow, with less template repetition. It does not guarantee lower cost, zero downtime or increased user activity.