DynamoDbDataSource

class aws_cdk.aws_appsync.DynamoDbDataSource(scope, id, *, read_only_access=None, table, use_caller_credentials=None, service_role=None, api, description=None, name=None)

Bases: aws_cdk.aws_appsync.BackedDataSource

(experimental) An AppSync datasource backed by a DynamoDB table.

Stability

experimental

Example:

api = appsync.GraphqlApi(self, "Api",
    name="demo",
    schema=appsync.Schema.from_asset(path.join(__dirname, "schema.graphql")),
    authorization_config=appsync.AuthorizationConfig(
        default_authorization=appsync.AuthorizationMode(
            authorization_type=appsync.AuthorizationType.IAM
        )
    ),
    xray_enabled=True
)

demo_table = dynamodb.Table(self, "DemoTable",
    partition_key=dynamodb.Attribute(
        name="id",
        type=dynamodb.AttributeType.STRING
    )
)

demo_dS = api.add_dynamo_db_data_source("demoDataSource", demo_table)

# Resolver for the Query "getDemos" that scans the DynamoDb table and returns the entire list.
demo_dS.create_resolver(
    type_name="Query",
    field_name="getDemos",
    request_mapping_template=appsync.MappingTemplate.dynamo_db_scan_table(),
    response_mapping_template=appsync.MappingTemplate.dynamo_db_result_list()
)

# Resolver for the Mutation "addDemo" that puts the item into the DynamoDb table.
demo_dS.create_resolver(
    type_name="Mutation",
    field_name="addDemo",
    request_mapping_template=appsync.MappingTemplate.dynamo_db_put_item(
        appsync.PrimaryKey.partition("id").auto(),
        appsync.Values.projecting("input")),
    response_mapping_template=appsync.MappingTemplate.dynamo_db_result_item()
)
Parameters
  • scope (Construct) –

  • id (str) –

  • read_only_access (Optional[bool]) – (experimental) Specify whether this DS is read only or has read and write permissions to the DynamoDB table. Default: false

  • table (ITable) – (experimental) The DynamoDB table backing this data source.

  • use_caller_credentials (Optional[bool]) – (experimental) use credentials of caller to access DynamoDB. Default: false

  • service_role (Optional[IRole]) – (experimental) The IAM service role to be assumed by AppSync to interact with the data source. Default: - Create a new role

  • api (IGraphqlApi) – (experimental) The API to attach this data source to.

  • description (Optional[str]) – (experimental) the description of the data source. Default: - None

  • name (Optional[str]) – (experimental) The name of the data source. Default: - id of data source

Stability

experimental

Methods

create_function(*, description=None, name, request_mapping_template=None, response_mapping_template=None)

(experimental) creates a new appsync function for this datasource and API using the given properties.

Parameters
  • description (Optional[str]) – (experimental) the description for this AppSync Function. Default: - no description

  • name (str) – (experimental) the name of the AppSync Function.

  • request_mapping_template (Optional[MappingTemplate]) – (experimental) the request mapping template for the AppSync Function. Default: - no request mapping template

  • response_mapping_template (Optional[MappingTemplate]) – (experimental) the response mapping template for the AppSync Function. Default: - no response mapping template

Stability

experimental

Return type

AppsyncFunction

create_resolver(*, field_name, pipeline_config=None, request_mapping_template=None, response_mapping_template=None, type_name)

(experimental) creates a new resolver for this datasource and API using the given properties.

Parameters
  • field_name (str) – (experimental) name of the GraphQL field in the given type this resolver is attached to.

  • pipeline_config (Optional[Sequence[IAppsyncFunction]]) – (experimental) configuration of the pipeline resolver. Default: - no pipeline resolver configuration An empty array | undefined sets resolver to be of kind, unit

  • request_mapping_template (Optional[MappingTemplate]) – (experimental) The request mapping template for this resolver. Default: - No mapping template

  • response_mapping_template (Optional[MappingTemplate]) – (experimental) The response mapping template for this resolver. Default: - No mapping template

  • type_name (str) – (experimental) name of the GraphQL type this resolver is attached to.

Stability

experimental

Return type

Resolver

to_string()

Returns a string representation of this construct.

Return type

str

Attributes

ds

(experimental) the underlying CFN data source resource.

Stability

experimental

Return type

CfnDataSource

grant_principal

(experimental) the principal of the data source to be IGrantable.

Stability

experimental

Return type

IPrincipal

name

(experimental) the name of the data source.

Stability

experimental

Return type

str

node

The construct tree node associated with this construct.

Return type

ConstructNode

Static Methods

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters

x (Any) –

Return type

bool