aws-cdk-lib.aws_appsync.AuthorizationType

enum AuthorizationType

LanguageType name
.NETAmazon.CDK.AWS.AppSync.AuthorizationType
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsappsync#AuthorizationType
Javasoftware.amazon.awscdk.services.appsync.AuthorizationType
Pythonaws_cdk.aws_appsync.AuthorizationType
TypeScript (source)aws-cdk-lib » aws_appsync » AuthorizationType

enum with all possible values for AppSync authorization type.

Example

const api = new appsync.GraphqlApi(this, 'Api', {
  name: 'demo',
  schema: appsync.SchemaFile.fromAsset(path.join(__dirname, 'schema.graphql')),
  authorizationConfig: {
    defaultAuthorization: {
      authorizationType: appsync.AuthorizationType.IAM,
    },
  },
  xrayEnabled: true,
});

const demoTable = new dynamodb.Table(this, 'DemoTable', {
  partitionKey: {
    name: 'id',
    type: dynamodb.AttributeType.STRING,
  },
});

const demoDS = api.addDynamoDbDataSource('demoDataSource', demoTable);

// Resolver for the Query "getDemos" that scans the DynamoDb table and returns the entire list.
// Resolver Mapping Template Reference:
// https://docs.aws.amazon.com/appsync/latest/devguide/resolver-mapping-template-reference-dynamodb.html
demoDS.createResolver('QueryGetDemosResolver', {
  typeName: 'Query',
  fieldName: 'getDemos',
  requestMappingTemplate: appsync.MappingTemplate.dynamoDbScanTable(),
  responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultList(),
});

// Resolver for the Mutation "addDemo" that puts the item into the DynamoDb table.
demoDS.createResolver('MutationAddDemoResolver', {
  typeName: 'Mutation',
  fieldName: 'addDemo',
  requestMappingTemplate: appsync.MappingTemplate.dynamoDbPutItem(
    appsync.PrimaryKey.partition('id').auto(),
    appsync.Values.projecting('input'),
  ),
  responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultItem(),
});

//To enable DynamoDB read consistency with the `MappingTemplate`:
demoDS.createResolver('QueryGetDemosConsistentResolver', {
  typeName: 'Query',
  fieldName: 'getDemosConsistent',
  requestMappingTemplate: appsync.MappingTemplate.dynamoDbScanTable(true),
  responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultList(),
});

Members

NameDescription
API_KEYAPI Key authorization type.
IAMAWS IAM authorization type.
USER_POOLCognito User Pool authorization type.
OIDCOpenID Connect authorization type.
LAMBDALambda authorization type.

API_KEY

API Key authorization type.


IAM

AWS IAM authorization type.

Can be used with Cognito Identity Pool federated credentials


USER_POOL

Cognito User Pool authorization type.


OIDC

OpenID Connect authorization type.


LAMBDA

Lambda authorization type.