A developer is deploying a serverless application using AWS SAM. The template contains a custom IAM role and a Lambda function configured as follows:
yaml
Transform: AWS::Serverless-2016-10-31
Resources:
ProcessDataFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs18.x
CodeUri: ./src
Role: !GetAtt CustomExecutionRole.Arn
CustomExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- apigateway.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: DynamoDBWritePolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- dynamodb:PutItem
Resource: '*'
During deployment, the CloudFormation stack creation fails with an error indicating that the Lambda function could not be created because AWS Lambda was unable to assume the configured role.
Which configuration change will resolve this deployment failure?
- ARemove the Transform: AWS::Serverless-2016-10-31 line from the template, as this declaration prevents CloudFormation from deploying standard AWS::IAM::Role resources.
- BModify the Lambda function's properties to use a custom integration rather than a proxy integration to allow the role context to pass through API Gateway.
- Modify the trust policy of CustomExecutionRole to specify lambda.amazonaws.com as the service principal in the Principal block.Cevap
- DIncrease the Timeout property of the ProcessDataFunction to ensure the Lambda execution environment has enough time to assume the IAM role during container initialization.