-
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
(aws-apigatewayv2-authorizers): Expose Authorizer ID to make it reusable from other projects #31605
(aws-apigatewayv2-authorizers): Expose Authorizer ID to make it reusable from other projects #31605
Comments
Makes sense to me. I think we can consider exposing the authorizer from here:
which is currently a private attribute
We welcome PRs and please help us prioritize with 👍 |
related to: V1533536242 |
@pahud I tried to access that variable, but it is undefined when you setup the autherizer. It's not until you attach it to the first HttpRoute that you actually get the token. But I guess that's "as designed", it might not be clear to everyone though. My workaround for now is to access the private HttpRoute.authBindResult for the first HttpRoute I assigned it to. But I guess I could also access it through the Authorizer AFTER the first binding. But it still feels a bit weird to have to do it after it's first usage and not after the construction. |
I can try to create a pr but I will need some guidance! I'll tag you in the PR when it's done. |
At this moment, I guess you'll need the trick like this export class HttplambdaStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Define the Lambda function for the authorizer
const authorizerFunction = new lambda.Function(this, 'AuthorizerFunction', {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'authorizer.handler',
code: lambda.Code.fromInline('dummy'),
});
// Define the Lambda function for the API endpoint
const apiFunction = new lambda.Function(this, 'ApiFunction', {
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'api.handler',
code: lambda.Code.fromInline('dummy'),
});
// Define the HTTP API
const httpApi = new apigatewayv2.HttpApi(this, 'HttpApi', {
apiName: 'MyHttpApi',
});
// Define the Lambda authorizer
const httpLambdaAuthorizer = new authorizers.HttpLambdaAuthorizer('LambdaAuthorizer', authorizerFunction, {
responseTypes: [authorizers.HttpLambdaResponseType.SIMPLE],
});
// Add a route with the Lambda authorizer
httpApi.addRoutes({
path: '/my-endpoint',
methods: [apigatewayv2.HttpMethod.GET],
integration: new integrations.HttpLambdaIntegration('ApiIntegration', apiFunction),
authorizer: httpLambdaAuthorizer,
});
const cfnauthorizer = httpApi.node.tryFindChild('LambdaAuthorizer')?.node.defaultChild as apigatewayv2.CfnAuthorizer
new cdk.CfnOutput(this, 'LambdaAuthorizerId', {
value: cfnauthorizer.ref,
description: 'The ID of the authorizer',
});
}
} Let me know if it works for you. |
@pahud : const authorizer = /* your authorizer code here*/;
const httpRoute = new HttpRoute(this, `HttpRoute`, {
httpApi: props.httpApi,
integration: props.integration,
authorizer: authorizer,
routeKey: HttpRouteKey.with(props.route, props.method)
});
const id = httpRoute['authBindResult'].authorizerId;
// or
const id = authorizer['authorizer'].authorizerId; |
@JonWallsten Agree. That's why I mentioned we need to make this public before we are allowed to do that and before that what I was offering could be a temporary workaround. That being said, there may be other concerns I haven't considered yet.
Feel free to submit a PR whenever you're ready, and we can move forward from there. Thank you. |
I see there's a corresponding PR created for this issue. Will follow up with the discussion in the PR. |
Comments on closed issues and PRs are hard for our team to see. |
1 similar comment
Comments on closed issues and PRs are hard for our team to see. |
Describe the feature
I need to be able to retrieve the Authorizer ID (the generated ID, not the one passed to the Construct) from the L2 construct.
Looking through the code I guess the issue is that the authorizer is not created until it's attached to a route. So I cannot personally create a PR for this since I don't know how references are resolved when the templates are generated.
Use Case
I want to be able to reuse the authorizer in other projects in the same account.
Proposed Solution
Expose the id the same way other constructs are.
Other Information
No response
Acknowledgements
CDK version used
2.159.0
Environment details (OS name and version, etc.)
Windows 11 23H2
The text was updated successfully, but these errors were encountered: