Class DynamoDbDataSource
An AppSync datasource backed by a DynamoDB table.
Implements
Inherited Members
Namespace: Amazon.CDK.AWS.AppSync
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class DynamoDbDataSource : BackedDataSource, IGrantable
Syntax (vb)
Public Class DynamoDbDataSource
Inherits BackedDataSource
Implements IGrantable
Remarks
ExampleMetadata: infused
Examples
var api = new GraphqlApi(this, "Api", new GraphqlApiProps {
Name = "demo",
Definition = Definition.FromFile(Join(__dirname, "schema.graphql")),
AuthorizationConfig = new AuthorizationConfig {
DefaultAuthorization = new AuthorizationMode {
AuthorizationType = AuthorizationType.IAM
}
},
XrayEnabled = true
});
var demoTable = new Table(this, "DemoTable", new TableProps {
PartitionKey = new Attribute {
Name = "id",
Type = AttributeType.STRING
}
});
var 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", new BaseResolverProps {
TypeName = "Query",
FieldName = "getDemos",
RequestMappingTemplate = MappingTemplate.DynamoDbScanTable(),
ResponseMappingTemplate = MappingTemplate.DynamoDbResultList()
});
// Resolver for the Mutation "addDemo" that puts the item into the DynamoDb table.
demoDS.CreateResolver("MutationAddDemoResolver", new BaseResolverProps {
TypeName = "Mutation",
FieldName = "addDemo",
RequestMappingTemplate = MappingTemplate.DynamoDbPutItem(PrimaryKey.Partition("id").Auto(), Values.Projecting("input")),
ResponseMappingTemplate = MappingTemplate.DynamoDbResultItem()
});
//To enable DynamoDB read consistency with the `MappingTemplate`:
demoDS.CreateResolver("QueryGetDemosConsistentResolver", new BaseResolverProps {
TypeName = "Query",
FieldName = "getDemosConsistent",
RequestMappingTemplate = MappingTemplate.DynamoDbScanTable(true),
ResponseMappingTemplate = MappingTemplate.DynamoDbResultList()
});
Synopsis
Constructors
Dynamo |
Used by jsii to construct an instance of this class from a Javascript-owned object reference |
Dynamo |
Used by jsii to construct an instance of this class from DeputyProps |
Dynamo |
Constructors
DynamoDbDataSource(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected DynamoDbDataSource(ByRefValue reference)
Parameters
- reference Amazon.
JSII. Runtime. Deputy. By Ref Value The Javascript-owned object reference
DynamoDbDataSource(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected DynamoDbDataSource(DeputyBase.DeputyProps props)
Parameters
- props Amazon.
JSII. Runtime. Deputy. Deputy Base. Deputy Props The deputy props
DynamoDbDataSource(Construct, String, IDynamoDbDataSourceProps)
public DynamoDbDataSource(Construct scope, string id, IDynamoDbDataSourceProps props)
Parameters
- scope Constructs.
Construct - id System.
String - props IDynamo
Db Data Source Props