3

I'm preparing a new AWS API Gateway under few environments - production, staging, testing, development.

Let's say I have two lambda functions connected to the GET /first and GET /second. Those resources are pointing to the lambda first:${stageVariables.Qualifier} (this variable has proper environment value depending on stage).

Now I have to add permissions for API Gateway to invoke both functions. AWS says:

You defined your Lambda function as a stage variable. Please ensure that you have the appropriate Function Policy on all functions you will use. You can do this by running the below AWS CLI command for each function, replacing the stage variable in the function-name parameter with the necessary function name.

aws lambda add-permission
    --function-name arn:aws:lambda:region:000...:function:first:${stageVariables.Qualifier}
    --source-arn arn:aws:execute-api:region:00000:xxxx/*/GET/first
    --principal apigateway.amazonaws.com
    --statement-id 0000-000-0-...
    --action lambda:InvokeFunction

So it's clear - I have to invoke this above command 8 times for each configuration:

first:development
first:testing
....
second:production

Is it possible somehow to add a general permission to allow invocation of any function in any qualifier with any path?

I'm aiming something like that (but it doesn't work):

aws lambda add-permission
    --function-name arn:aws:lambda:region:000...:function:*:*
    --source-arn arn:aws:execute-api:region:00000:xxxx/*/*/*
    --principal apigateway.amazonaws.com
    --statement-id 0000-000-0-...
    --action lambda:InvokeFunction
hsz
  • 148,279
  • 62
  • 259
  • 315
  • wholesale configuration and management of your cloud deployments is really what tools like CloudFormat, TerraForm et al was born to do. – Kim Burgaard Mar 31 '18 at 19:06
  • @KimBurgaard I think the question was more of -- can I just create a policy in IAM and attach it to all lambdas, instead of executing a command that does essentially that. BTW -- inaccessibly. – ZenMaster Sep 06 '18 at 11:50

0 Answers0