I set up my Amazon API Gateway API to execute an AWS Lambda function using a stage variable. But now when I invoke the method, my API returns a 500 status code with the message "Internal server error." How can I fix this?

If you build an API with Lambda integration using the API Gateway console, the console automatically requests to add the required permissions for standard Lambda integration. In contrast, when you set up a stage variable to call a Lambda function through your API, you must manually grant your API the permission to invoke the Lambda function. For a stage variable, the API Gateway console notifies you of a sample command that you must run outside the console to set up this permission.

If your Lambda function's resource policy doesn't include the permission for your API to invoke the function, your API returns a 500 status code with the message "Internal server error." To verify that the 500 status code is returned because the permission to invoke the function is missing, check your API Gateway execution logs for a message similar to "Invalid permissions on Lambda function."

To resolve the "Invalid permissions on Lambda function" issue, run this AWS Command Line Interface (AWS CLI) command to add the lambda:InvokeFunction permission for your API in the Lambda function's resource policy:

Warning: Before you run this command, you must replace the values for --function-name and --source-arn with the correct values for your Lambda function and API, respectively. You must also replace the value for --statement-id with a unique statement identifier. For more information, see add-permission.

aws lambda add-permission --function-name arn:aws:lambda:us-east-1:youraccount-id:function:yourlambdafunction --source-arn arn:aws:execute-api:us-east-1:youraccount-id:api-id/*/GET/lambdasv1 --principal apigateway.amazonaws.com --statement-id statement-id-guid --action lambda:InvokeFunction

Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center

Published: 2018-11-06