Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

The CDK Construct Library for AWS::AppSync

Project description

AWS AppSync Construct Library


cfn-resources: Stable

All classes with the Cfn prefix in this module (CFN Resources) are always stable and safe to use.

cdk-constructs: Experimental

The APIs of higher level constructs in this module are experimental and under active development. They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and breaking changes will be announced in the release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.

The @aws-cdk/aws-appsync package contains constructs for building flexible APIs that use GraphQL.


Example of a GraphQL API with AWS_IAM authorization resolving into a DynamoDb backend data source.

GraphQL schema file schema.graphql:

type demo {
  id: String!
  version: String!
type Query {
  getDemos: [ test! ]
input DemoInput {
  version: String!
type Mutation {
  addDemo(input: DemoInput!): demo

CDK stack file app-stack.ts:

# Example automatically generated without compilation. See
import aws_cdk.aws_appsync as appsync
import aws_cdk.aws_dynamodb as db

api = appsync.GraphQLApi(stack, "Api",
    schema_definition_file=join(__dirname, "schema.graphql"),

demo_table = db.Table(stack, "DemoTable",

demo_dS = api.add_dynamo_db_data_source("demoDataSource", "Table for Demos\"", demo_table)

# Resolver for the Query "getDemos" that scans the DyanmoDb table and returns the entire list.

# Resolver for the Mutation "addDemo" that puts the item into the DynamoDb table.
    request_mapping_template=MappingTemplate.dynamo_db_put_item(PrimaryKey.partition("id").auto(), Values.projecting("demo")),


When using AWS_IAM as the authorization type for GraphQL API, an IAM Role with correct permissions must be used for access to API.

When configuring permissions, you can specify specific resources to only be accessible by IAM authorization. For example, if you want to only allow mutability for IAM authorized access you would configure the following.

In schema.graphql:

# Example automatically generated without compilation. See
type Mutation {
  updateExample(...): ...@aws_iam


   "Version": "2012-10-17",
   "Statement": [
         "Effect": "Allow",
         "Action": [
         "Resource": [

See documentation for more details.

To make this easier, CDK provides grant API.

Use the grant function for more granular authorization.

# Example automatically generated without compilation. See
role = iam.Role(stack, "Role",
api = appsync.GraphQLApi(stack, "API",

api.grant(role, appsync.IamResource.custom("types/Mutation/fields/updateExample"), "appsync:GraphQL")


In order to use the grant functions, you need to use the class IamResource.

  • IamResource.custom(...arns) permits custom ARNs and requires an argument.
  • IamResouce.ofType(type, ...fields) permits ARNs for types and their fields.
  • IamResource.all() permits ALL resources.

Generic Permissions

Alternatively, you can use more generic grant functions to accomplish the same usage.

These include:

  • grantMutation (use to grant access to Mutation fields)
  • grantQuery (use to grant access to Query fields)
  • grantSubscription (use to grant access to Subscription fields)
# Example automatically generated without compilation. See
# For generic types
api.grant_mutation(role, "updateExample")

# For custom types and granular design
api.grant(role, appsync.IamResource.of_type("Mutation", "updateExample"), "appsync:GraphQL")

Project details

Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for, version 1.59.0
Filename, size File type Python version Upload date Hashes
Filename, size aws_cdk.aws_appsync-1.59.0-py3-none-any.whl (176.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size (177.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page