aws-cdk-lib.aws_appsync.AttributeValues

class AttributeValues

LanguageType name
.NETAmazon.CDK.AWS.AppSync.AttributeValues
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsappsync#AttributeValues
Javasoftware.amazon.awscdk.services.appsync.AttributeValues
Pythonaws_cdk.aws_appsync.AttributeValues
TypeScript (source)aws-cdk-lib » aws_appsync » AttributeValues

Specifies the attribute value assignments.

Example

const api = new appsync.GraphqlApi(this, 'Api', {
  name: 'demo',
  schema: appsync.SchemaFile.fromAsset(path.join(__dirname, 'schema.graphql')),
  authorizationConfig: {
    defaultAuthorization: {
      authorizationType: appsync.AuthorizationType.IAM,
    },
  },
  xrayEnabled: true,
});

const demoTable = new dynamodb.Table(this, 'DemoTable', {
  partitionKey: {
    name: 'id',
    type: dynamodb.AttributeType.STRING,
  },
});

const 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', {
  typeName: 'Query',
  fieldName: 'getDemos',
  requestMappingTemplate: appsync.MappingTemplate.dynamoDbScanTable(),
  responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultList(),
});

// Resolver for the Mutation "addDemo" that puts the item into the DynamoDb table.
demoDS.createResolver('MutationAddDemoResolver', {
  typeName: 'Mutation',
  fieldName: 'addDemo',
  requestMappingTemplate: appsync.MappingTemplate.dynamoDbPutItem(
    appsync.PrimaryKey.partition('id').auto(),
    appsync.Values.projecting('input'),
  ),
  responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultItem(),
});

//To enable DynamoDB read consistency with the `MappingTemplate`:
demoDS.createResolver('QueryGetDemosConsistentResolver', {
  typeName: 'Query',
  fieldName: 'getDemosConsistent',
  requestMappingTemplate: appsync.MappingTemplate.dynamoDbScanTable(true),
  responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultList(),
});

Initializer

new AttributeValues(container: string, assignments?: Assign[])

Parameters

  • container string
  • assignments Assign[]

Methods

NameDescription
attribute(attr)Allows assigning a value to the specified attribute.
renderTemplate()Renders the attribute value assingments to a VTL string.
renderVariables()Renders the variables required for renderTemplate.

attribute(attr)

public attribute(attr: string): AttributeValuesStep

Parameters

  • attr string

Returns

  • AttributeValuesStep

Allows assigning a value to the specified attribute.


renderTemplate()

public renderTemplate(): string

Returns

  • string

Renders the attribute value assingments to a VTL string.


renderVariables()

public renderVariables(): string

Returns

  • string

Renders the variables required for renderTemplate.