AWS SAM CLI enhances local serverless development with CloudFormation Language Extensions
AWS SAM CLI now supports CloudFormation Language Extensions, streamlining local serverless development by reducing template duplication and allowing for efficient resource iteration.
The AWS Serverless Application Model (SAM) Command Line Interface (CLI) now includes support for AWS CloudFormation Language Extensions. This new feature helps developers minimize repetition in their infrastructure as code (IaC) templates while maintaining a complete local development experience. By allowing resources to be defined once and iterated locally, the development process for serverless applications is accelerated as it removes the need to wait for cloud deployments.
Typically, developers need to define several similar resources, such as AWS Lambda functions, DynamoDB tables, or SNS topics, within a single template. Previously, those using SAM CLI for building, testing, and deploying serverless applications could not process templates that incorporated CloudFormation Language Extensions. This limitation forced a choice between reducing template duplication and utilizing SAM CLI for local development. With the latest update, SAM CLI can process Language Extensions in memory for local use while keeping the original template intact for CloudFormation deployments. This allows developers to define resources once and test them locally with all SAM CLI commands, identifying errors such as syntax issues or missing dependencies before deployment. This enhancement shortens iteration cycles and decreases the time spent troubleshooting failed cloud deployments.
To begin using this feature, download or update SAM CLI to the latest version. Include the AWS::LanguageExtensions transform in your SAM template and utilize Fn::ForEach to generate multiple resources from a single definition. Commands like sam build, sam local invoke, sam sync, sam local start-api, and sam validate will automatically expand these loops and process each generated resource. Developers can invoke expanded functions by name, such as sam local invoke AlphaFunction. Additionally, SAM CLI now supports functions like Fn::Length, Fn::ToJsonString, Fn::FindInMap with DefaultValue, and conditional attributes such as DeletionPolicy and UpdateReplacePolicy.
For further information, developers can consult the SAM CLI developer guide and the accompanying launch blog post.