Using AWS Lambda Alias with API Gateway

Using AWS lambda with specific alias through API Gateway; as described here with a command like:

aws lambda add-permission --function-name arn:aws:lambda:us-east-1:xxxxxx:function:getData --source-arn arn:aws:execute-api:us-east-1:xxxxxx:t463p6g84d/*/POST/data --principal --statement-id  --action lambda:InvokeFunction

Resulted in an error

aws: error: argument operation: Invalid choice, valid choices are:

The cause was the following could be due to the following:

The CLI command must be issued with credentials that have permission to call the “add-permission” action of the Lambda APIs.

However; I still couldn’t quite get it to work.  What did work; was adding `API Endpoint` from Lambda’s console; which assigns the necessarily permissions; seems that you can change endpoint later on and the permission will still work (I guess they are not attached to a specific endpoint).  Also don’t forget to re-deploy your API once you’ve made the changes.




Add Permission to Lambda Function

You defined your Lambda function as a stage variable; you must manually give permissions to all the 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:us-east-1:1111111111:function:getSectorData:${stageVariables.lambdaAlias} –source-arn arn:aws:execute-api:us-east-1:1111111111:111/*/POST/data –principal –statement-id 111-4f1f-b5e5-111 –action lambda:InvokeFunction



About Neil Rubens

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *