aws-cdk-lib.aws_appsync.MappingTemplate

class MappingTemplate

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

MappingTemplates for AppSync resolvers.

Example

const api = new appsync.GraphqlApi(stack, 'EventBridgeApi', {
  name: 'EventBridgeApi',
  schema: appsync.SchemaFile.fromAsset(path.join(__dirname, 'appsync.eventbridge.graphql')),
});

const bus = new events.EventBus(stack, 'DestinationEventBus', {});

const dataSource = api.addEventBridgeDataSource('NoneDS', bus);

dataSource.createResolver('EventResolver', {
  typeName: 'Mutation',
  fieldName: 'emitEvent',
  requestMappingTemplate: appsync.MappingTemplate.fromFile('request.vtl'),
  responseMappingTemplate: appsync.MappingTemplate.fromFile('response.vtl'),
});

Initializer

new MappingTemplate()

Methods

NameDescription
renderTemplate()this is called to render the mapping template to a VTL string.
static dynamoDbDeleteItem(keyName, idArg)Mapping template to delete a single item from a DynamoDB table.
static dynamoDbGetItem(keyName, idArg, consistentRead?)Mapping template to get a single item from a DynamoDB table.
static dynamoDbPutItem(key, values)Mapping template to save a single item to a DynamoDB table.
static dynamoDbQuery(cond, indexName?, consistentRead?)Mapping template to query a set of items from a DynamoDB table.
static dynamoDbResultItem()Mapping template for a single result item from DynamoDB.
static dynamoDbResultList()Mapping template for a result list from DynamoDB.
static dynamoDbScanTable(consistentRead?)Mapping template to scan a DynamoDB table to fetch all entries.
static fromFile(fileName)Create a mapping template from the given file.
static fromString(template)Create a mapping template from the given string.
static lambdaRequest(payload?, operation?)Mapping template to invoke a Lambda function.
static lambdaResult()Mapping template to return the Lambda result to the caller.

renderTemplate()

public renderTemplate(): string

Returns

  • string

this is called to render the mapping template to a VTL string.


static dynamoDbDeleteItem(keyName, idArg)

public static dynamoDbDeleteItem(keyName: string, idArg: string): MappingTemplate

Parameters

  • keyName string — the name of the hash key field.
  • idArg string — the name of the Mutation argument.

Returns

  • MappingTemplate

Mapping template to delete a single item from a DynamoDB table.


static dynamoDbGetItem(keyName, idArg, consistentRead?)

public static dynamoDbGetItem(keyName: string, idArg: string, consistentRead?: boolean): MappingTemplate

Parameters

  • keyName string — the name of the hash key field.
  • idArg string — the name of the Query argument.
  • consistentRead boolean

Returns

  • MappingTemplate

Mapping template to get a single item from a DynamoDB table.


static dynamoDbPutItem(key, values)

public static dynamoDbPutItem(key: PrimaryKey, values: AttributeValues): MappingTemplate

Parameters

  • key PrimaryKey — the assigment of Mutation values to the primary key.
  • values AttributeValues — the assignment of Mutation values to the table attributes.

Returns

  • MappingTemplate

Mapping template to save a single item to a DynamoDB table.


static dynamoDbQuery(cond, indexName?, consistentRead?)

public static dynamoDbQuery(cond: KeyCondition, indexName?: string, consistentRead?: boolean): MappingTemplate

Parameters

  • cond KeyCondition — the key condition for the query.
  • indexName string
  • consistentRead boolean

Returns

  • MappingTemplate

Mapping template to query a set of items from a DynamoDB table.


static dynamoDbResultItem()

public static dynamoDbResultItem(): MappingTemplate

Returns

  • MappingTemplate

Mapping template for a single result item from DynamoDB.


static dynamoDbResultList()

public static dynamoDbResultList(): MappingTemplate

Returns

  • MappingTemplate

Mapping template for a result list from DynamoDB.


static dynamoDbScanTable(consistentRead?)

public static dynamoDbScanTable(consistentRead?: boolean): MappingTemplate

Parameters

  • consistentRead boolean

Returns

  • MappingTemplate

Mapping template to scan a DynamoDB table to fetch all entries.


static fromFile(fileName)

public static fromFile(fileName: string): MappingTemplate

Parameters

  • fileName string

Returns

  • MappingTemplate

Create a mapping template from the given file.


static fromString(template)

public static fromString(template: string): MappingTemplate

Parameters

  • template string

Returns

  • MappingTemplate

Create a mapping template from the given string.


static lambdaRequest(payload?, operation?)

public static lambdaRequest(payload?: string, operation?: string): MappingTemplate

Parameters

  • payload string — the VTL template snippet of the payload to send to the lambda.
  • operation string — the type of operation AppSync should perform on the data source.

Returns

  • MappingTemplate

Mapping template to invoke a Lambda function.


static lambdaResult()

public static lambdaResult(): MappingTemplate

Returns

  • MappingTemplate

Mapping template to return the Lambda result to the caller.