Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I've been all over the web searching for an answer to this.

Essentially, we're spinning up an API using Swagger, which is awesome and works great, but one thing doesn't work... When we make a call to an Endpoint, we get a 500 error (it's not a 500 error that we're providing either it's one from AWS). The error states "Execution failed due to configuration error: Invalid permissions on Lambda function" (youtu.be/H4LM_jw5zzs <- This is a video, from another user, of the error I'm getting). 

I've gone down many ratholes, and have found an answer... It involves using the AWS CLI and looks a bit like this:

aws lambda add-permission \

--function-name FUNCTION_NAME \

--statement-id STATEMENT_ID \

--action lambda:InvokeFunction \

--principal apigateway.amazonaws.com \

--source-arn "arn:aws:execute-api:us-east-1:ACCOUNT_ID:API_ID/*/METHOD/ENDPOINT"

This is great and all, but we are using CloudFormation to spin up everything and we want this to be automated. Is there an easier way to go about this? Is there something in CloudFormation that will give us the resource policy that we need? 

I'm hitting a bit of a wall with this, but I've been working on it for a few hours today and it's a bit of a blocker for our API release, so any help would be much appreciated.

1 Answer

0 votes
by (44.4k points)

This CloudFormation snippet could solve this problem:

"Permission": {

    "Type": "AWS::Lambda::Permission",

    "Properties": {

        "FunctionName": { "Fn::GetAtt": [ "Lambda", "Arn" ] },

        "Action": "lambda:InvokeFunction",

        "Principal": "apigateway.amazonaws.com",

        "SourceArn": { "Fn::Join": [ "", [

            "arn:aws:execute-api:",

            { "Ref": "AWS::Region" }, ":",

            { "Ref": "AWS::AccountId" }, ":",

            { "Ref": "API" },

            "/*/*/*"

        ] ] }

    }

}

The permission to launch your Lambda function is granted to API Gateway. Lambda (line 4) and API (line 11) are the variables which have to be changed.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...