class MappingTemplate
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.AppSync.MappingTemplate |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsappsync#MappingTemplate |
Java | software.amazon.awscdk.services.appsync.MappingTemplate |
Python | aws_cdk.aws_appsync.MappingTemplate |
TypeScript (source) | aws-cdk-lib » aws_appsync » MappingTemplate |
MappingTemplates for AppSync resolvers.
Example
import * as events from 'aws-cdk-lib/aws-events';
const api = new appsync.GraphqlApi(this, 'EventBridgeApi', {
name: 'EventBridgeApi',
definition: appsync.Definition.fromFile(path.join(__dirname, 'appsync.eventbridge.graphql')),
});
const bus = new events.EventBus(this, '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
Name | Description |
---|---|
render | this is called to render the mapping template to a VTL string. |
static dynamo | Mapping template to delete a single item from a DynamoDB table. |
static dynamo | Mapping template to get a single item from a DynamoDB table. |
static dynamo | Mapping template to save a single item to a DynamoDB table. |
static dynamo | Mapping template to query a set of items from a DynamoDB table. |
static dynamo | Mapping template for a single result item from DynamoDB. |
static dynamo | Mapping template for a result list from DynamoDB. |
static dynamo | Mapping template to scan a DynamoDB table to fetch all entries. |
static from | Create a mapping template from the given file. |
static from | Create a mapping template from the given string. |
static lambda | Mapping template to invoke a Lambda function. |
static lambda | Mapping template to return the Lambda result to the caller. |
Template()
renderpublic renderTemplate(): string
Returns
string
this is called to render the mapping template to a VTL string.
DbDeleteItem(keyName, idArg)
static dynamopublic 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
Mapping template to delete a single item from a DynamoDB table.
DbGetItem(keyName, idArg, consistentRead?)
static dynamopublic 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
Mapping template to get a single item from a DynamoDB table.
DbPutItem(key, values)
static dynamopublic static dynamoDbPutItem(key: PrimaryKey, values: AttributeValues): MappingTemplate
Parameters
- key
Primary
— the assigment of Mutation values to the primary key.Key - values
Attribute
— the assignment of Mutation values to the table attributes.Values
Returns
Mapping template to save a single item to a DynamoDB table.
DbQuery(cond, indexName?, consistentRead?)
static dynamopublic static dynamoDbQuery(cond: KeyCondition, indexName?: string, consistentRead?: boolean): MappingTemplate
Parameters
- cond
Key
— the key condition for the query.Condition - indexName
string
- consistentRead
boolean
Returns
Mapping template to query a set of items from a DynamoDB table.
DbResultItem()
static dynamopublic static dynamoDbResultItem(): MappingTemplate
Returns
Mapping template for a single result item from DynamoDB.
DbResultList()
static dynamopublic static dynamoDbResultList(): MappingTemplate
Returns
Mapping template for a result list from DynamoDB.
DbScanTable(consistentRead?)
static dynamopublic static dynamoDbScanTable(consistentRead?: boolean): MappingTemplate
Parameters
- consistentRead
boolean
Returns
Mapping template to scan a DynamoDB table to fetch all entries.
File(fileName)
static frompublic static fromFile(fileName: string): MappingTemplate
Parameters
- fileName
string
Returns
Create a mapping template from the given file.
String(template)
static frompublic static fromString(template: string): MappingTemplate
Parameters
- template
string
Returns
Create a mapping template from the given string.
Request(payload?, operation?)
static lambdapublic 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
Mapping template to invoke a Lambda function.
Result()
static lambdapublic static lambdaResult(): MappingTemplate
Returns
Mapping template to return the Lambda result to the caller.