Skip to content
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

API Gateway: CDK fails to attach a cognito user pool authorizer to the construct #29535

Open
sdpoueme opened this issue Mar 19, 2024 · 3 comments
Labels
@aws-cdk/aws-cognito Related to Amazon Cognito bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@sdpoueme
Copy link

sdpoueme commented Mar 19, 2024

Describe the bug

After defining a Cognito HalAuthorizer in openapi yaml (security Schema and endpoint) and attempting to correlate that with a CognitoUserPoolAuthorizer created in an API Gateway construct, the follow error results:

RuntimeError: Error: Resolution error: Resolution error: Resolution error: Authorizer (xxxxxxStack/xxxApiDevConstruct/HalAuthorizer) must be attached to a RestApi.
Object creation stack:

Expected Behavior

The Authorizer should be attached to the REST API and the CDK deployment should succeed.

Current Behavior

CDK fails to attach the Cognito Authorizer and the Rest API creation is inconsistent.

Reproduction Steps

  1. Create a Cognito Authorizer in CDK and attach it to the API Gateway
authorizer = apigateway.CognitoUserPoolsAuthorizer(self, "myAuthorizer", cognito_user_pools=[user_pool]) 

See #7377, which is related to the same issue but mention a case where separate stacks are used.

Possible Solution

The bug seems to be in CognitoUserPoolsAuthorizer object and related to the following lines:

api_gateway_to_lambda = OpenApiGatewayToLambda(self,
                                                       id="OpenApiGatewayToLambda",
                                                       api_integrations=[api_integration],
                                                       api_definition_asset=api_definition_asset,
                                                       api_gateway_props=rest_api_base_props)

Additional Information/Context

No response

CDK CLI Version

2.130.0 (build bd6e5ee)

Framework Version

Python 3.11.2

Node.js Version

N/A

OS

MacOS

Language

Python 3.11.2

Language Version

Python 3.11.2

Other information

No response

@sdpoueme sdpoueme added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 19, 2024
@github-actions github-actions bot added the @aws-cdk/aws-cognito Related to Amazon Cognito label Mar 19, 2024
@pahud
Copy link
Contributor

pahud commented Mar 20, 2024

Hi

I won't be able to reproduce this from the provided reproduction steps. Are you able to provide more details about your code with least required properties so I can reproduce this in my environment?

@pahud pahud added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Mar 20, 2024
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Mar 22, 2024
@ruvimrd
Copy link
Contributor

ruvimrd commented Mar 22, 2024

Some simple replication code:

const userPool = UserPool.fromUserPoolArn(this, "userPool", <userPoolArn>);
const authorizer = new CognitoUserPoolsAuthorizer(this, "testAuthorizer", {
  cognitoUserPools: [userPool],
});

const api = new LambdaRestApi(this, "testRestAPI", props, {
  handler: this.function,
  proxy: false,
  defaultMethodOptions: {
    authorizer: authorizer,
    authorizationType: AuthorizationType.COGNITO
  }
});

This should give the same error as above.

It seems like this is running into a similar issue as #7377 because adding authorizer._attachToApi(api) fixes it.

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cognito Related to Amazon Cognito bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

3 participants