$ show aws/serverless-application-model
The AWS Serverless Application Model (SAM) Transformer is a Python library that converts SAM templates into AWS CloudFormation templates. It serves as the core transformation engine for the AWS SAM CLI, enabling developers to define serverless applications using SAM syntax that gets expanded to standard CloudFormation resources. The system follows a modular architecture with distinct layers for parsing, validation, transformation, and resource generation, featuring an extensible plugin system for adding custom transformation logic. Key capabilities include intrinsic function resolution (!Ref, !GetAtt, !Sub), globals and conditions processing, policy template expansion, and resource-specific transformations for AWS services like Lambda, API Gateway, Step Functions, and more.
The LLM identified 5 files worth highlighting for reuse:
Implements a clean plugin architecture with lifecycle events (before_transform_template, before_transform_resource, after_transform_template). The BasePlugin class defines hook points, and specific plugins like GlobalsPlugin and PolicyTemplatesPlugin implement transformation logic. This pattern allows extending SAM functionality without modifying core code and could be reused in other template processing systems.
Resolves CloudFormation intrinsic functions (!Ref, !GetAtt, !Sub, !FindInMap) during template processing. The resolver separates intrinsic detection from execution, with specific actions implemented in actions.py. This self-contained component handles a complex but common problem in infrastructure-as-code tools and could be extracted for use in other template processors.
Converts SAM policy templates into concrete IAM statements with parameter substitution. The processor handles template parsing, variable resolution, and statement generation, enabling least-privilege permissions from reusable policy templates. This solves a recurring security concern in IaC and could be applied to other policy generation scenarios.
Defines a consistent resource modeling pattern where each AWS resource type inherits from a base Resource class, declares property_types and runtime_attrs, and implements to_cloudformation() for transformation. This abstraction is used across Lambda, API, StateMachine, and other resources, providing a clean separation between SAM specification and CloudFormation generation.
Provides utilities for traversing and modifying nested template structures with path-based access. Includes functions for getting, setting, and deleting values at arbitrary paths in dictionaries, handling intrinsic functions appropriately. This solves a common problem in template processing and could be reused in any system working with hierarchical configuration data.