Reputation: 26574
I created a resource in Amazon's ApiGateway. It is pointing to a Lambda function. This is being hit by a native mobile application (android and ios) which is already in the wild.
I now want to modify the Lambda function, but I see no way to change my ApiGateway resource to point to an alias of the lambda. This is my first time playing with any of these technologies and I see no easy mechanism to manage this in the aws console.
How can I modify my ApiGateway resource to point to my lambda alias so I can edit trunk without affecting existing clients?
Upvotes: 49
Views: 35486
Reputation: 1989
Posting this for prosperity. @Raghav - if you are using SAM or CloudFormation.Setup the function with alias:
Type: AWS::Serverless::Function
Properties:
PackageType: Image
MemorySize: 256
AutoPublishAlias: live
Then in your API gateway config during routes, change uri from:
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${YourFunction.Arn}/invocations"
And add :live after the Arn:
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${YourFunction.Arn}:live/invocations"
If you don't add the lambda alias, everything still looked okay (in the CloudFormation UI and Gateway), but calling gave me:
x-amzn-errortype: InternalServerErrorException
{"message": "Internal server error"}
Upvotes: 0
Reputation: 2406
On the Api Gateway console, use ARN instead of a lambda function name.
Upvotes: 7
Reputation: 21
For my case, I would add directly the arn of the lambda function to replace the Lambda name. This works for me without have to to add the {} notation.
Upvotes: 2
Reputation: 2559
For the later googler, be careful to add permissions WITH the correct alias like yourfunc:prod not only yourfunc. That means if you'r planning to use 3 alias to invoke the lambda functions, you have to add 3 of them.
Upvotes: 9
Reputation: 5983
Under Integration Type -> Lambda Function you need to add a reference to the stage variable MyLambdaFuntionName:${stageVariables.lambdaAlias}
and then for each stage set the lambdaAlias
in the Stage Variables tab accordingly(lambdaAlias=dev, lambdaAlias=prod, etc.)
There is an example with screenshots here: https://aws.amazon.com/blogs/compute/using-api-gateway-stage-variables-to-manage-lambda-functions/
Its kind of hidden towards the very bottom of the page starting with "Alternatively, you can mix and match static names"
Upvotes: 61