-
Notifications
You must be signed in to change notification settings - Fork 4k
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
(aws_apigatewayv2.HttpLambdaIntegration): add_routes integration to subroute doesn't take affect #18965
Comments
I can verify this also exists in the javascript/typescript version of CDK and the same workaround works. |
This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
This still needs addressing. |
@mitchboulay can you confirm that this issue still exists for you? I tried replicating this issue with an Integ Test by creating an import { HttpApi, HttpMethod } from '@aws-cdk/aws-apigatewayv2-alpha';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { ExpectedResult, IntegTest } from '@aws-cdk/integ-tests-alpha';
import { App, Stack } from 'aws-cdk-lib';
import { HttpLambdaIntegration } from '../../lib';
const app = new App();
const stack = new Stack(app, 'integ-lambda-proxy');
const httpApi = new HttpApi(stack, 'test-apigwv2-add-subroute-integration');
const lambdaHandler = new lambda.Function(stack, 'AlwaysSuccess - FirstRoute', {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'index.handler',
code: new lambda.InlineCode('exports.handler = async function(event, context) { return { statusCode: 200, body: \'success - hit this lambda\' }; };'),
});
const lambdaHandlerIntegration = new HttpLambdaIntegration('my-lambda-integration', lambdaHandler);
httpApi.addRoutes({
path: '/firstroute',
methods: [HttpMethod.GET],
integration: lambdaHandlerIntegration,
});
httpApi.addRoutes({
path: '/firstroute/subroute',
methods: [HttpMethod.GET],
integration: lambdaHandlerIntegration,
});
const integ = new IntegTest(app, 'Integ', { testCases: [stack] });
integ.assertions.httpApiCall(httpApi.apiEndpoint + '/firstroute').expect(ExpectedResult.objectLike({
status: 200,
body: 'success - hit this lambda',
}));
integ.assertions.httpApiCall(httpApi.apiEndpoint + '/firstroute/subroute').expect(ExpectedResult.objectLike({
status: 200,
body: 'success - hit this lambda',
})); Which version of CDK are you using? Perhaps this was fixed in a more recent version. |
@mitchboulay I was able to replicate your issue using an imported lambda function as you did above. The issue here is that imported lambdas are not able to add permissions unless they belong to the same account/region as the lambda we are importing from. So, A workaround for this is to use const myLambdaHandler: lambda.Function;
const lambdaFromFunctionAttributes = lambda.Function.fromFunctionAttributes(stack, 'my-referenced-lambda`, {
functionArn: myLambdaHandler.functionArn,
sameEnvironment: true,
}); After the linked PR merges, you will be able to use the const myLambdaHandler: lambda.Function;
const lambdaFromFunctionName = lambda.Function.fromFunctionName(stack, 'my-referenced-lambda-from-name', 'my-lambda-handler'); |
Brilliant @sumupitchayan , much appreciated! |
…ions do not get configured (#27861) Closes #18965 `HTTPLambdaIntegration` using imported lambda functions are currently not being configured. This is due to the fact that the `canCreatePermissions` property is set to false in imported lambdas, so the lambda permissions are never created. This PR fixes this issue by: - Setting the `sameEnvironment` property to `true` for lambdas imported using `fromFunctionName()` - Adding clarification in documentation about imported lambdas needing to belong to the same stack account and region as that of the lambda being imported from be able to add permissions - Adding a new warning to be thrown when the `addPermissions()` function is called on a lambda with `canCreatePermissions` set to false. The new integ test file tests that imported lambdas using `fromFunctionName()` and `fromFunctionAttributes()` (with `sameEnvironment` set to `true`) work as expected, including on sub-route integrations. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
What is the problem?
Given (Pre configuration required):
from aws_cdk.aws_apigatewayv2_integrations import HttpLambdaIntegration
API gateway configured with routes & subroutes, connected to a lambda function via CDK (Python)
Looks like a stack is not accepting multiple
aws_apigatewayv2.HttpApi.add_routes()
as done below in test.pyWhen (Action taken): Function looked up via
Function.from_function_arn
and applied to integration parameter ofhttp_api.add_routes
Reproduction Steps
app.py
test.py
What did you expect to happen?
Then (Expected behavior, per documentation): Route has lambda integration defined, attached and working.
What actually happened?
Actual (Observed behavior): Route gains integration ID and appears to have function assigned to it but this is not the case. This is verified by navigating to the lambda function under Configuration, the sub-route is not defined as an endpoint.
CDK CLI Version
2.8.0 (build 8a5eb49)
Framework Version
No response
Node.js Version
v14.17.3
OS
MacOS
Language
Python
Language Version
Python 3.9.8
Other information
This looks to be an issue with the
add_routes
method as thefrom_function_arn
works for the authorizer.Workaround:
The text was updated successfully, but these errors were encountered: