A developer is writing an AWS SAM template for a serverless application. The application contains a Lambda function (`ProcessOrdersFunction`) that must execute with a custom IAM role to comply with strict organizational security requirements. The developer defines the custom role and the function in the SAM template as follows:
yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: apigateway.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: DynamoDBWriteAccess
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- dynamodb:PutItem
Resource: !GetAtt OrdersTable.Arn
ProcessOrdersFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Handler: index.handler
Runtime: nodejs18.x
Role: !GetAtt LambdaExecutionRole.Arn
OrdersTable:
Type: AWS::Serverless::SimpleTable
During deployment, the stack is created successfully. However, when the client application triggers the Lambda function, the function fails to execute, and the logs indicate that the execution role cannot be assumed. What is the root cause of this execution failure?
- AThe template is missing the required AWS CloudFormation Transform declaration, which prevents AWS SAM from correctly compiling the custom IAM role.
- BThe function does not define a custom execution timeout, causing AWS Lambda to reject the role assumption request.
- The trust policy on the custom role specifies the service principal for API Gateway (apigateway.amazonaws.com) rather than AWS Lambda (lambda.amazonaws.com).Cevap
- DThe API Gateway Lambda Proxy integration requires the execution role's trust policy to authorize the API Gateway service instead of the Lambda service.