Class PrimaryKey
Specifies the assignment to the primary key.
Namespace: Amazon.CDK.AWS.AppSync
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class PrimaryKey : DeputyBase
Syntax (vb)
Public Class PrimaryKey
Inherits DeputyBase
Remarks
It either contains the full primary key or only the partition key.
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
PrimaryKey(Assign, Assign) | |
PrimaryKey(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
PrimaryKey(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
Properties
Pkey |
Methods
Partition(String) | Allows assigning a value to the partition key. |
RenderTemplate() | Renders the key assignment to a VTL string. |
Constructors
PrimaryKey(Assign, Assign)
PrimaryKey(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected PrimaryKey(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
PrimaryKey(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected PrimaryKey(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
Properties
Pkey
Methods
Partition(String)
Allows assigning a value to the partition key.
public static PartitionKeyStep Partition(string key)
Parameters
- key System.String
Returns
RenderTemplate()
Renders the key assignment to a VTL string.
public virtual string RenderTemplate()
Returns
System.String