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 .
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
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'
});
}
}
$ cdk deploy
Cannot read property 'length' of undefined
Subprocess exited with error 1
$
Sample code 2 works fine.
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.
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
Most helpful comment
NOTE: In the new version I also had to switch off a couple of eslint warnings on the authorizationType as follows:
This occurs with TypeScript 3.9.5 and eslint 7.2.0