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

(AppSync): The "Cannot read property 'length' of undefined" error is displayed when the defaultAuthorization setting. #8666

Closed
dozonot opened this issue Jun 20, 2020 · 1 comment · Fixed by #8673
Assignees
Labels
@aws-cdk/aws-appsync Related to AWS AppSync bug This issue is a bug. in-progress This issue is being actively worked on. needs-triage This issue or PR still needs to be triaged.

Comments

@dozonot
Copy link

dozonot commented Jun 20, 2020

❓ General Issue

I'm trying the AppSync authentication settings.
I want to use Cognito authentication. No additional authentication settings are required.
A similar setup worked in version 1.45.0, but did not work in 1.46.0 .

The Question

Sample code 1 outputs error 1.
The sample code has been modified for the breaking changes in version 1.46.0 It is.
feat(appsync): enhances and completes auth config #7878

  • Sample code 1
import * as cdk from '@aws-cdk/core';
import * as appsync from '@aws-cdk/aws-appsync';
import * as cognito from '@aws-cdk/aws-cognito';

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

    const userPool = new cognito.UserPool(this, 'userPool', {
      userPoolName: 'userPool',
    });

    const api = new appsync.GraphQLApi(this, 'api', {
      name: 'graphQlApi',
      authorizationConfig: {
        defaultAuthorization: {
          authorizationType: appsync.AuthorizationType.USER_POOL,
          userPoolConfig: {
            userPool,
            defaultAction: appsync.UserPoolDefaultAction.ALLOW
          }
        }
      },
      schemaDefinitionFile: './graphql/schema.graphql'
    });
  }
}
  • Error 1
$ cdk deploy
Cannot read property 'length' of undefined
Subprocess exited with error 1
$

Sample code 2 works fine.

  • Sample code 2
import * as cdk from '@aws-cdk/core';
import * as appsync from '@aws-cdk/aws-appsync';
import * as cognito from '@aws-cdk/aws-cognito';

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

    const userPool = new cognito.UserPool(this, 'userPool', {
      userPoolName: 'userPool',
    });

    const api = new appsync.GraphQLApi(this, 'api', {
      name: 'graphQlApi',
      authorizationConfig: {
        defaultAuthorization: {
          authorizationType: appsync.AuthorizationType.USER_POOL,
          userPoolConfig: {
            userPool,
            defaultAction: appsync.UserPoolDefaultAction.ALLOW
          }
        },
        additionalAuthorizationModes: []   // Add this configuration
      },
      schemaDefinitionFile: './graphql/schema.graphql'
    });
  }
}

When setting defaultAuthorization, it seems that you need to specify additionalAuthorizationModes, even if you don't need the additional authentication features.
(1.45.0 is additionalAuthorizationModes to There was no need to configure it.

Is this behavior expected?
Sorry if I missed the documentation.
I was confused by the configuration, so I created an Issue.

Environment

  • CDK CLI Version: 1.46.0
  • Module Version: 1.46.0
  • Node.js Version: 12.18.0 (npm 6.14.5)
  • OS: Ubuntu 20.04
  • Language (Version): TypeScript
@asnaseer-resilient
Copy link

asnaseer-resilient commented Jun 22, 2020

NOTE: In the new version I also had to switch off a couple of eslint warnings on the authorizationType as follows:

    const graphQlApi = new cdkAppsync.GraphQLApi(this, 'GraphQL', {
      ...,
      authorizationConfig: {
        defaultAuthorization: {
          // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
          authorizationType: cdkAppsync.AuthorizationType.USER_POOL,
          userPoolConfig: {
            userPool,
            defaultAction: cdkAppsync.UserPoolDefaultAction.ALLOW
          }
        },
        additionalAuthorizationModes: []     // <--- workaround here
      }
    });

This occurs with TypeScript 3.9.5 and eslint 7.2.0

@SomayaB SomayaB added in-progress This issue is being actively worked on. bug This issue is a bug. labels Jun 22, 2020
@mergify mergify bot closed this as completed in #8673 Jun 23, 2020
mergify bot pushed a commit that referenced this issue Jun 23, 2020
…odes' is undefined (#8673)

fix(appsync): Not to throw an Error even if 'additionalAuthorizationModes' is undefined

fixes #8666 #8668

----

*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-appsync Related to AWS AppSync bug This issue is a bug. in-progress This issue is being actively worked on. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants