-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating an API Gateway endpoint with a stage variable using a Lambda.Function.lambda_from_arn in AWS CDK doesn't work #30098
Comments
This looks like an error from CFN. Can you run |
There is a difference. When the API Gateway resource is created from a Lambda that was created in that stack, the FucntionName looks like this:
But when I get a Lambda using Function.lambda_from_arn, to then create the resource in another stack, the FunctionName looks like this:
In the case above it works, but when I define a stage variable, it looks like this, and the error occurs:
|
UPDATE: Got it working, and now the CDK is behaving like we were expecting, what we do is the following: So everything works, but I'm doing something the documentation directly tells me isn't recommended
But for the case where I'm trying to use a Lambda that was created from another stack to create a API Gateway resource, I'm doing it like this
And doing this works, everything works fine. BUT I'm not gonna close this issue, because in the CDK documentation, it specifically says that AwsIntegration is intended for calling all AWS service actions, but is not recommended for calling a Lambda function, because the Lambda custom integration is a legacy technology. So everything works, but I'm doing something the documentation directly tells me isn't recommended |
An alternative solution I used is to change the Integration.uri once the method has been integrated with the lambda integration using the cfnMethod.addPropertyOverride
This will replace the invocation URI integrating the stagevariable as an alias |
Describe the bug
When using Lambda.Function.function_from_arn() to get an AWS Lambda that was created from a previously created stack, so that in another stack to create an AWS ApiGateway resource referencing to the stage variable does not work.
When I'm doing this, without specifying a stage variable, everything works without any problem.was created
Expected Behavior
The API Gateway resource Lambda integration, with a stage variable, is to be created, because that is what happens when I create the AWS Lambda and use it to create an API Gateway resource in the same stack.an
Current Behavior
This works
Reproduction Steps
This doesn't work
And I get the following error:
[#/FunctionName: string [arn:aws:lambda:eu-west-1:668526471736:function:OtherStackLambd:${stageVariables.lambdaAlias}] does not match pattern ^(arn:(aws[a-zA-Z-]*)?:lambda:)?([a-z]{2}((-gov)|(-iso([a-z]?)))?-[a-z]+-\d{1}:)?(\d{12}:)?(function:)?([a-zA-Z0-9-_]+)(:(\$LATEST|[a-zA-Z0-9-_]+))?$]
, when I was expecting for this to create the endpoint like in the other case.Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.54.0
Framework Version
V1
Node.js Version
v14.20.0
OS
Linux
Language
Python
Language Version
Python 3.9.13
Other information
No response
The text was updated successfully, but these errors were encountered: