Question

Difficulty: EasyAWS Serverless Application Model (SAM)

A developer is creating an AWS Serverless Application Model (SAM) template to deploy a Lambda function that is triggered by an API Gateway endpoint. Which two template configurations or declarations are required to successfully define the serverless function and its API Gateway trigger?

  1. Include the `Transform: AWS::Serverless-2016-10-31` declaration at the root of the templateAnswer
  2. Define an `Events` property of type `Api` under the `AWS::Serverless::Function` resourceAnswer
  3. C
    Declare `AWS::Serverless-2016-10-31` as the value for the `AWSTemplateFormatVersion` property
  4. D
    Configure a custom integration mapping template to manually structure the HTTP request payload for the API Gateway endpoint
  5. E
    Configure the trust policy of the Lambda execution role to allow the API Gateway principal (`apigateway.amazonaws.com`) to assume the role

Answer

To configure the serverless function and its API Gateway trigger, the developer must include the `Transform: AWS::Serverless-2016-10-31` declaration at the root of the template and define an `Events` property of type `Api` under the `AWS::Serverless::Function` resource.
The correct configurations are including the `Transform: AWS::Serverless-2016-10-31` declaration at the root of the template to instruct CloudFormation to evaluate the SAM syntax, and defining an `Events` property of type `Api` under the `AWS::Serverless::Function` resource to set up the API Gateway trigger.

Step-by-Step Solution

1
Identify the required header declaration for AWS SAM templates.
Adding `Transform: AWS::Serverless-2016-10-31` instructs CloudFormation to parse the template using the SAM engine.
Without the Transform declaration, CloudFormation fails to recognize shorthand SAM resource types like AWS::Serverless::Function.
2
Configure the event source to trigger the Lambda function.
Adding an `Events` property with an `Api` type under the function resource establishes the API Gateway connection.
This automatically creates and links the API Gateway resource to the function with sensible default proxy configurations.

Key Concept

AWS Serverless Application Model (SAM) Template Structure
Rate this question