A developer is configuring an Amazon API Gateway REST API with a Lambda integration. To manage deployments across different environments, the developer defines a stage variable named and configures the integration request to dynamically target a Lambda function alias using the format `my-function: env 500$ Internal Server Error. The API Gateway execution logs show a permission error when attempting to invoke the Lambda function. Which action should the developer take to resolve this issue?
- Use the AWS CLI to run the `aws lambda add-permission` command, granting the API Gateway service principal (`apigateway.amazonaws.com`) permission to perform the `lambda:InvokeFunction` action on the specific Lambda function alias.Answer
- BUpdate the Lambda function's execution role trust policy to allow the API Gateway service principal (`apigateway.amazonaws.com`) to assume the role.
- CEnable Lambda Proxy Integration in the integration request to allow API Gateway to bypass Lambda resource-based policy checks.
- DConfigure a VTL mapping template in the Integration Request to forward the stage variables inside the request payload.
Answer
Use the AWS CLI to run the `aws lambda add-permission` command, granting the API Gateway service principal (`apigateway.amazonaws.com`) permission to perform the `lambda:InvokeFunction` action on the specific Lambda function alias.
The correct answer is correct because when you use stage variables to dynamically specify a Lambda function in API Gateway, the console cannot automatically add the resource-based policy permission to the Lambda function. You must manually grant invocation permissions to the API Gateway service principal (`apigateway.amazonaws.com`) using the `aws lambda add-permission` command for the specific alias that will be resolved at runtime.
Step-by-Step Solution
Key Concept
API Gateway stage variables and resource-based invocation permissions for Lambda integrations