Question

Difficulty: MediumAWS Serverless Application Model (SAM)

A cloud engineer is deploying a serverless microservice using an AWS Serverless Application Model (SAM) template. During the deployment process, the AWS CloudFormation engine returns an error stating that the resource type `AWS::Serverless::Function` is not supported or is invalid.

The template contains the following configuration:

yaml
AWSTemplateFormatVersion: '2010-09-09'

Resources:
GetProductFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs18.x
CodeUri: ./src
Events:
GetProductApi:
Type: Api
Properties:
Path: /products/{id}
Method: get

Which of the following configuration adjustments will resolve this deployment error?

  1. A
    Modify the event source properties to use a custom Integration type instead of the default proxy integration.
  2. B
    Configure an explicit IAM Role with a trust policy that allows the API Gateway service principal to assume the execution role.
  3. Add the `Transform: AWS::Serverless-2016-10-31` declaration at the root level of the template.Answer
  4. D
    Specify a larger timeout value under the Globals section of the template to prevent deployment timeouts.

Answer

Add the `Transform: AWS::Serverless-2016-10-31` declaration at the root level of the template.
Adding the `Transform` declaration at the root level of the template allows AWS CloudFormation to process the SAM template. The template is converted into standard CloudFormation resources, resolving the error where `AWS::Serverless::Function` is unrecognized.

Step-by-Step Solution

1
Analyze the error message returned by CloudFormation.
The parser fails because it does not recognize the custom resource type `AWS::Serverless::Function`.
CloudFormation by default only supports standard AWS resource types unless a transform macro is declared.
2
Identify the missing requirement for AWS SAM templates.
The template is missing the mandatory `Transform` header.
The Transform header specifies the macro that AWS CloudFormation uses to translate the SAM template into a compliant CloudFormation template.
3
Insert the Transform statement at the root level.
The template now contains `Transform: AWS::Serverless-2016-10-31`.
This allows CloudFormation to resolve SAM shorthand syntax like `AWS::Serverless::Function` into standard AWS Lambda and IAM resources.

Key Concept

AWS Serverless Application Model (SAM) template transformation
Estimated Time:1m 15s
Rate this question