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

@aws-cdk/aws-apigatewayv2-authorizers-alpha: can't apply lambda defaultAuthorizer #27436

Closed
uttrasey opened this issue Oct 6, 2023 · 3 comments · Fixed by #27576
Closed

@aws-cdk/aws-apigatewayv2-authorizers-alpha: can't apply lambda defaultAuthorizer #27436

uttrasey opened this issue Oct 6, 2023 · 3 comments · Fixed by #27576
Labels
@aws-cdk/aws-apigatewayv2-authorizers Related to aws-apigatewayv2-authorizers package @aws-cdk/aws-apigatewayv2-integrations Related to AWS APIGatewayv2 Integrations @aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 bug This issue is a bug. p2

Comments

@uttrasey
Copy link

uttrasey commented Oct 6, 2023

Describe the bug

Hey 👋

I can't assign a defaultAuthorizer to all routes on a HttpAPI. cdk deploy runs with no problems but it's not created.

    // build a lambda - this gets created ✅
    const authLambda = new lambdaNodejs.NodejsFunction(this, 'auth-lambda', {
      entry: './src/custom-auth-lambda.ts',
      handler: 'handler',
      runtime: lambda.Runtime.NODEJS_18_X,
      environment: {
        NODE_OPTIONS: '--enable-source-maps',
      },
    });

    // Authorizer Target - this does not show up in API authorizer list ❌
    const lambdaAuthorizer = new HttpLambdaAuthorizer('MyAuthorizer', authLambda, {
      responseTypes: [HttpLambdaResponseType.SIMPLE], 
    });

    // the API - none of the subsequently deployed routes are authorized ❌
    const httpApi = new apigwv2alpha.HttpApi(this, 'my-http-api', {
      apiName: 'my-api',
      createDefaultStage: true,
      defaultDomainMapping: {
        domainName: domain,
      },
      defaultAuthorizer: lambdaAuthorizer
    });

    // Add a route... this is done in another part of the app. Route created but not auth'd ❌
    const route = new apigwv2alpha.HttpRoute(this, 'my-route', {
      httpApi: httpApi,
      routeKey: apigwv2alpha.HttpRouteKey.with('/v1/mything/{proxy+}', apigwv2alpha.HttpMethod.ANY),
      integration: new HttpAlbIntegration('my-app-private-integration', props.service.listener, {
        vpcLink: vpcLink
      })
    })

Expected Behavior

I'd expect the created route to be authorized by my lambda

Current Behavior

No authorizer either in AWS console or in practice. No authorizer listed under manage Authorizers for the API either

Reproduction Steps

See above

Possible Solution

Not sure

Additional Information/Context

{
  "devDependencies": {
    "@aws-cdk/aws-apigatewayv2-alpha": "^2.99.1-alpha.0",
    "@aws-cdk/aws-apigatewayv2-authorizers-alpha": "^2.99.1-alpha.0",
    "@aws-cdk/aws-apigatewayv2-integrations-alpha": "^2.99.1-alpha.0",
    "@types/aws-lambda": "^8.10.123",
    "@types/jest": "^29.5.4",
    "@types/node": "20.5.9",
    "aws-cdk": "2.96.2",
    "aws-cdk-lib": "2.99.1",
    "constructs": "^10.0.0",
    "jest": "^29.6.4",
    "source-map-support": "^0.5.21",
    "ts-jest": "^29.1.1",
    "ts-node": "^10.9.1",
    "typescript": "~5.2.2"
  },
  "dependencies": {
    "aws-lambda": "^1.0.7"
  }
}

CDK CLI Version

2.99.1 (build b2a895e)

Framework Version

No response

Node.js Version

18

OS

MAC

Language

TypeScript

Language Version

No response

Other information

No response

@uttrasey uttrasey added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 6, 2023
@github-actions github-actions bot added the @aws-cdk/aws-apigatewayv2-authorizers Related to aws-apigatewayv2-authorizers package label Oct 6, 2023
@indrora
Copy link
Contributor

indrora commented Oct 12, 2023

@indrora indrora added p2 @aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 @aws-cdk/aws-apigatewayv2-integrations Related to AWS APIGatewayv2 Integrations and removed needs-triage This issue or PR still needs to be triaged. labels Oct 12, 2023
@rix0rrr
Copy link
Contributor

rix0rrr commented Oct 13, 2023

Looks like defaultAuthorizer is only respected if you call httpApi.addRoutes(), not if you use new apigwv2alpha.HttpRoute().

authorizer: options.authorizer ?? this.defaultAuthorizer,

Would make sense to fix, I think. This is unexpected behavior.

@mergify mergify bot closed this as completed in #27576 Oct 27, 2023
mergify bot pushed a commit that referenced this issue Oct 27, 2023
…27576)

This PR fixes a bug that `defaultAuthorizer` cannot be applied to `HttpRoute` without an authorizer.

Closes #27436.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

mrgrain pushed a commit that referenced this issue Nov 1, 2023
…27576)

This PR fixes a bug that `defaultAuthorizer` cannot be applied to `HttpRoute` without an authorizer.

Closes #27436.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigatewayv2-authorizers Related to aws-apigatewayv2-authorizers package @aws-cdk/aws-apigatewayv2-integrations Related to AWS APIGatewayv2 Integrations @aws-cdk/aws-apigatewayv2 Related to Amazon API Gateway v2 bug This issue is a bug. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants