DynamoDbDataSource
- class aws_cdk.aws_appsync.DynamoDbDataSource(scope, id, *, table, read_only_access=None, use_caller_credentials=None, service_role=None, api, description=None, name=None)
Bases:
BackedDataSourceAn AppSync datasource backed by a DynamoDB table.
- ExampleMetadata:
infused
Example:
api = appsync.GraphqlApi(self, "Api", name="demo", definition=appsync.Definition.from_file(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. # Resolver Mapping Template Reference: # https://docs.aws.amazon.com/appsync/latest/devguide/resolver-mapping-template-reference-dynamodb.html demo_dS.create_resolver("QueryGetDemosResolver", 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("MutationAddDemoResolver", 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() ) # To enable DynamoDB read consistency with the `MappingTemplate`: demo_dS.create_resolver("QueryGetDemosConsistentResolver", type_name="Query", field_name="getDemosConsistent", request_mapping_template=appsync.MappingTemplate.dynamo_db_scan_table(True), response_mapping_template=appsync.MappingTemplate.dynamo_db_result_list() )
- Parameters:
scope (
Construct)id (
str)table (
ITable) – The DynamoDB table backing this data source.read_only_access (
Optional[bool]) – Specify whether this DS is read only or has read and write permissions to the DynamoDB table. Default: falseuse_caller_credentials (
Optional[bool]) – use credentials of caller to access DynamoDB. Default: falseservice_role (
Optional[IRole]) – The IAM service role to be assumed by AppSync to interact with the data source. Default: - Create a new roleapi (
IGraphqlApi) – The API to attach this data source to.description (
Optional[str]) – the description of the data source. Default: - Nonename (
Optional[str]) – The name of the data source. Default: - id of data source
Methods
- create_function(id, *, name, code=None, description=None, max_batch_size=None, request_mapping_template=None, response_mapping_template=None, runtime=None)
creates a new appsync function for this datasource and API using the given properties.
- Parameters:
id (
str)name (
str) – the name of the AppSync Function.code (
Optional[Code]) – The function code. Default: - no code is useddescription (
Optional[str]) – the description for this AppSync Function. Default: - no descriptionmax_batch_size (
Union[int,float,None]) – The maximum number of resolver request inputs that will be sent to a single AWS Lambda function in a BatchInvoke operation. Can only be set when using LambdaDataSource. Default: - No max batch sizerequest_mapping_template (
Optional[MappingTemplate]) – the request mapping template for the AppSync Function. Default: - no request mapping templateresponse_mapping_template (
Optional[MappingTemplate]) – the response mapping template for the AppSync Function. Default: - no response mapping templateruntime (
Optional[FunctionRuntime]) – The functions runtime. Default: - no function runtime, VTL mapping templates used
- Return type:
- create_resolver(id, *, field_name, type_name, caching_config=None, code=None, max_batch_size=None, pipeline_config=None, request_mapping_template=None, response_mapping_template=None, runtime=None)
creates a new resolver for this datasource and API using the given properties.
- Parameters:
id (
str)field_name (
str) – name of the GraphQL field in the given type this resolver is attached to.type_name (
str) – name of the GraphQL type this resolver is attached to.caching_config (
Union[CachingConfig,Dict[str,Any],None]) – The caching configuration for this resolver. Default: - No caching configurationcode (
Optional[Code]) – The function code. Default: - no code is usedmax_batch_size (
Union[int,float,None]) – The maximum number of elements per batch, when using batch invoke. Default: - No max batch sizepipeline_config (
Optional[Sequence[IAppsyncFunction]]) – configuration of the pipeline resolver. Default: - no pipeline resolver configuration An empty array | undefined sets resolver to be of kind, unitrequest_mapping_template (
Optional[MappingTemplate]) – The request mapping template for this resolver. Default: - No mapping templateresponse_mapping_template (
Optional[MappingTemplate]) – The response mapping template for this resolver. Default: - No mapping templateruntime (
Optional[FunctionRuntime]) – The functions runtime. Default: - no function runtime, VTL mapping templates used
- Return type:
- to_string()
Returns a string representation of this construct.
- Return type:
str
Attributes
- PROPERTY_INJECTION_ID = 'aws-cdk-lib.aws-appsync.DynamoDbDataSource'
- ds
the underlying CFN data source resource.
- grant_principal
the principal of the data source to be IGrantable.
- name
the name of the data source.
- node
The tree node.
Static Methods
- classmethod is_construct(x)
Checks if
xis a construct.Use this method instead of
instanceofto properly detectConstructinstances, even when the construct library is symlinked.Explanation: in JavaScript, multiple copies of the
constructslibrary on disk are seen as independent, completely different libraries. As a consequence, the classConstructin each copy of theconstructslibrary is seen as a different class, and an instance of one class will not test asinstanceofthe other class.npm installwill not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of theconstructslibrary can be accidentally installed, andinstanceofwill behave unpredictably. It is safest to avoid usinginstanceof, and using this type-testing method instead.- Parameters:
x (
Any) – Any object.- Return type:
bool- Returns:
true if
xis an object created from a class which extendsConstruct.