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