Question #866
A company is migrating its legacy applications to a serverless architecture using AWS SAM. The development team must ensure their AWS CloudFormation templates correctly define serverless resources while adhering to AWS SAM best practices. What is the critical step required in the CloudFormation templates to enable the use of AWS SAM-specific resource definitions?
Define all serverless resources in the Resources section using AWS::Lambda::Function and AWS::ApiGateway::RestApi.
Include a Globals section in the CloudFormation templates to specify common configurations for AWS SAM resources.
Add a Transform section declaring the AWS::Serverless-2016-10-31 transform to process AWS SAM syntax.
Use a Mappings section to reference preconfigured AWS SAM resource templates stored in Amazon S3.
Explanation
The correct answer is C. To enable AWS SAM-specific resource definitions (e.g., AWS::Serverless::Function instead of AWS::Lambda::Function), CloudFormation templates must include a Transform section with the value AWS::Serverless-2016-10-31. This transform instructs CloudFormation to process the template using AWS SAM's macros, which interpret SAM's simplified syntax and convert it into standard CloudFormation resources.
Why other options are incorrect:
- A: Using AWS::Lambda::Function and AWS::ApiGateway::RestApi bypasses SAM's abstractions, defeating the purpose of SAM's simplified syntax.
- B: The Globals section is optional for shared configurations (e.g., common Lambda settings) but not required to enable SAM resource definitions.
- D: AWS SAM does not require preconfigured templates in S3; the Transform section handles SAM syntax processing.
Key Takeaway: The Transform section is mandatory in SAM templates to enable AWS SAM's higher-level resource definitions.
Answer
The correct answer is: C