Infrastructure as Code – the AWS Serverless Application Model (AWS SAM) - Serverless Architectures with AWS Lambda

Infrastructure as Code – the AWS Serverless Application Model (AWS SAM)

Representing your infrastructure as code brings many benefits in terms of the auditability, automatability, and repeatability of managing the creation and modification of infrastructure. Even though you don’t need to manage any infrastructure when building a serverless application, many components play a role in the architecture: IAM roles, Lambda functions and their configurations, their event sources, and other dependencies. Representing all of these things in AWS CloudFormation natively would require a large amount of JSON or YAML. Much of it would be almost identical from one serverless application to the next.

The AWS Serverless Application Model (AWS SAM) enables you to have a simpler experience when building serverless applications and get the benefits of infrastructure as code. AWS SAM is an open specification abstraction layer on top of AWS CloudFormation. It provides a set of command line utilities that enable you to define a full serverless application stack with only a handful of lines of JSON or YAML, package your Lambda function code together with that infrastructure definition, and then deploy them together to AWS. We recommend using AWS SAM combined with AWS CloudFormation to define and make changes to your serverless application environment.

There is a distinction, however, between changes that occur at the infrastructure/environment level and application code changes occurring within existing Lambda functions. AWS CloudFormation and AWS SAM aren’t the only tools required to build a deployment pipeline for your Lambda function code changes. See the CI/CD section of this whitepaper for more recommendations about managing code changes for your Lambda functions.