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 Authoriser - Name is optional, but still required #8038

Closed
gvhuyssteen opened this issue May 16, 2020 · 4 comments
Closed

API Gateway Authoriser - Name is optional, but still required #8038

gvhuyssteen opened this issue May 16, 2020 · 4 comments
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made. effort/small Small work item – less than a day of effort needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p2

Comments

@gvhuyssteen
Copy link

Creating an Api Gateway Cognito Authoriser results in an error if the name parameter is not passed in.

I added a working solution to indicate that the name is indeed

Reproduction Steps

#!/usr/bin/env node
import * as apigateway from '@aws-cdk/aws-apigateway';
import * as cognito from '@aws-cdk/aws-cognito';
import * as lambda from '@aws-cdk/aws-lambda';
import * as cdk from '@aws-cdk/core';

export class AuthoriserNameRequiredStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const api = new apigateway.RestApi(this, 'api');

    const demo = api.root.addResource('demo');

    const pool = new cognito.UserPool(this, 'pool', { userPoolName: 'authoriser-name-required-userpool' });

    const cognitoAuthorizer = new apigateway.CfnAuthorizer(this, 'cfnAuth', {
      restApiId: api.restApiId,
      type: 'COGNITO_USER_POOLS',
      identitySource: 'method.request.header.Authorization',
      providerArns: [pool.userPoolArn],
    });

    const lambdaFunction = new lambda.Function(this, 'lambda-demo', {
      code: new lambda.AssetCode('src'),
      handler: 'demo.handler',
      runtime: lambda.Runtime.NODEJS_12_X
    });

    const lambdaFunctionIntegration = new apigateway.LambdaIntegration(lambdaFunction);

    demo.addMethod('GET', lambdaFunctionIntegration, {
      authorizationType: apigateway.AuthorizationType.COGNITO,
      authorizer: {
        authorizerId: cognitoAuthorizer.ref
      }
    });

  }
}

const app = new cdk.App();
new AuthoriserNameRequiredStack(app, 'AuthoriserNameRequiredStack', {env: {region: 'eu-west-1'}});

Working Solution

...
    const cognitoAuthorizer = new apigateway.CfnAuthorizer(this, 'cfnAuth', {
      restApiId: api.restApiId,
      name: 'cognito-authoriser',   // Added name
      type: 'COGNITO_USER_POOLS',
      identitySource: 'method.request.header.Authorization',
      providerArns: [pool.userPoolArn],
    });
...

Error Log

  9/16 
      | 10:14:19 PM
      | CREATE_IN_PROGRESS
      | AWS::ApiGateway::Authorizer
      | cfnAuth
 10/16
      | 10:14:19 PM
      | CREATE_FAILED 
      | AWS::ApiGateway::Authorizer
      | cfnAuth 1 validation error detected: Value null at 'createAuthorizerInput.name' failed to satisfy constraint:
        Member must not be null (Service: AmazonApiGateway; Status Code: 400; Error Code: ValidationException; )

Environment

  • CLI Version: 1.39.0 (build 5d727c1)
  • OS : macOS Catalina 10.15.4
  • Language : Typescript

Other

AWS::ApiGateway::Authorizer name

PR making the name property optional


This is 🐛 Bug Report

@gvhuyssteen gvhuyssteen added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 16, 2020
@SomayaB SomayaB added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label May 18, 2020
@nija-at nija-at removed the needs-triage This issue or PR still needs to be triaged. label May 20, 2020
@nija-at
Copy link
Contributor

nija-at commented May 20, 2020

This is a bug in the CloudFormation spec which reports that the Name property is optional.
Internal ref: i/CFN-32071

We can however patch this on our end by adding a new patch file here - https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/cfnspec/spec-source.

@nija-at nija-at added the p2 label May 20, 2020
@nija-at nija-at added needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. effort/small Small work item – less than a day of effort labels Aug 6, 2020
@github-actions
Copy link

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.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jun 17, 2022
@peterwoodworth
Copy link
Contributor

name is specified as required now in resource spec

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made. effort/small Small work item – less than a day of effort needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p2
Projects
None yet
Development

No branches or pull requests

4 participants