Class MappingTemplate
java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.services.appsync.MappingTemplate
- All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable
@Generated(value="jsii-pacmak/1.104.0 (build e79254c)",
date="2024-11-27T16:50:53.249Z")
@Stability(Stable)
public abstract class MappingTemplate
extends software.amazon.jsii.JsiiObject
MappingTemplates for AppSync resolvers.
Example:
// Build a data source for AppSync to access the database. GraphqlApi api; // Create username and password secret for DB Cluster DatabaseSecret secret = DatabaseSecret.Builder.create(this, "AuroraSecret") .username("clusteradmin") .build(); // The VPC to place the cluster in Vpc vpc = new Vpc(this, "AuroraVpc"); // Create the serverless cluster, provide all values needed to customise the database. ServerlessCluster cluster = ServerlessCluster.Builder.create(this, "AuroraCluster") .engine(DatabaseClusterEngine.AURORA_MYSQL) .vpc(vpc) .credentials(Map.of("username", "clusteradmin")) .clusterIdentifier("db-endpoint-test") .defaultDatabaseName("demos") .build(); RdsDataSource rdsDS = api.addRdsDataSource("rds", cluster, secret, "demos"); // Set up a resolver for an RDS query. rdsDS.createResolver("QueryGetDemosRdsResolver", BaseResolverProps.builder() .typeName("Query") .fieldName("getDemosRds") .requestMappingTemplate(MappingTemplate.fromString("\n {\n \"version\": \"2018-05-29\",\n \"statements\": [\n \"SELECT * FROM demos\"\n ]\n }\n ")) .responseMappingTemplate(MappingTemplate.fromString("\n $utils.toJson($utils.rds.toJsonObject($ctx.result)[0])\n ")) .build()); // Set up a resolver for an RDS mutation. rdsDS.createResolver("MutationAddDemoRdsResolver", BaseResolverProps.builder() .typeName("Mutation") .fieldName("addDemoRds") .requestMappingTemplate(MappingTemplate.fromString("\n {\n \"version\": \"2018-05-29\",\n \"statements\": [\n \"INSERT INTO demos VALUES (:id, :version)\",\n \"SELECT * WHERE id = :id\"\n ],\n \"variableMap\": {\n \":id\": $util.toJson($util.autoId()),\n \":version\": $util.toJson($ctx.args.version)\n }\n }\n ")) .responseMappingTemplate(MappingTemplate.fromString("\n $utils.toJson($utils.rds.toJsonObject($ctx.result)[1][0])\n ")) .build());
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
-
Constructor Summary
ModifierConstructorDescriptionprotected
protected
MappingTemplate
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
MappingTemplate
(software.amazon.jsii.JsiiObjectRef objRef) -
Method Summary
Modifier and TypeMethodDescriptionstatic MappingTemplate
dynamoDbDeleteItem
(String keyName, String idArg) Mapping template to delete a single item from a DynamoDB table.static MappingTemplate
dynamoDbGetItem
(String keyName, String idArg) Mapping template to get a single item from a DynamoDB table.static MappingTemplate
dynamoDbGetItem
(String keyName, String idArg, Boolean consistentRead) Mapping template to get a single item from a DynamoDB table.static MappingTemplate
dynamoDbPutItem
(PrimaryKey key, AttributeValues values) Mapping template to save a single item to a DynamoDB table.static MappingTemplate
dynamoDbQuery
(KeyCondition cond) Mapping template to query a set of items from a DynamoDB table.static MappingTemplate
dynamoDbQuery
(KeyCondition cond, String indexName) Mapping template to query a set of items from a DynamoDB table.static MappingTemplate
dynamoDbQuery
(KeyCondition cond, String indexName, Boolean consistentRead) Mapping template to query a set of items from a DynamoDB table.static MappingTemplate
Mapping template for a single result item from DynamoDB.static MappingTemplate
Mapping template for a result list from DynamoDB.static MappingTemplate
Mapping template to scan a DynamoDB table to fetch all entries.static MappingTemplate
dynamoDbScanTable
(Boolean consistentRead) Mapping template to scan a DynamoDB table to fetch all entries.static MappingTemplate
Create a mapping template from the given file.static MappingTemplate
fromString
(String template) Create a mapping template from the given string.static MappingTemplate
Mapping template to invoke a Lambda function.static MappingTemplate
lambdaRequest
(String payload) Mapping template to invoke a Lambda function.static MappingTemplate
lambdaRequest
(String payload, String operation) Mapping template to invoke a Lambda function.static MappingTemplate
Mapping template to return the Lambda result to the caller.abstract String
this is called to render the mapping template to a VTL string.Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Constructor Details
-
MappingTemplate
protected MappingTemplate(software.amazon.jsii.JsiiObjectRef objRef) -
MappingTemplate
protected MappingTemplate(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
MappingTemplate
@Stability(Stable) protected MappingTemplate()
-
-
Method Details
-
dynamoDbDeleteItem
@Stability(Stable) @NotNull public static MappingTemplate dynamoDbDeleteItem(@NotNull String keyName, @NotNull String idArg) Mapping template to delete a single item from a DynamoDB table.- Parameters:
keyName
- the name of the hash key field. This parameter is required.idArg
- the name of the Mutation argument. This parameter is required.
-
dynamoDbGetItem
@Stability(Stable) @NotNull public static MappingTemplate dynamoDbGetItem(@NotNull String keyName, @NotNull String idArg, @Nullable Boolean consistentRead) Mapping template to get a single item from a DynamoDB table.- Parameters:
keyName
- the name of the hash key field. This parameter is required.idArg
- the name of the Query argument. This parameter is required.consistentRead
-
-
dynamoDbGetItem
@Stability(Stable) @NotNull public static MappingTemplate dynamoDbGetItem(@NotNull String keyName, @NotNull String idArg) Mapping template to get a single item from a DynamoDB table.- Parameters:
keyName
- the name of the hash key field. This parameter is required.idArg
- the name of the Query argument. This parameter is required.
-
dynamoDbPutItem
@Stability(Stable) @NotNull public static MappingTemplate dynamoDbPutItem(@NotNull PrimaryKey key, @NotNull AttributeValues values) Mapping template to save a single item to a DynamoDB table.- Parameters:
key
- the assigment of Mutation values to the primary key. This parameter is required.values
- the assignment of Mutation values to the table attributes. This parameter is required.
-
dynamoDbQuery
@Stability(Stable) @NotNull public static MappingTemplate dynamoDbQuery(@NotNull KeyCondition cond, @Nullable String indexName, @Nullable Boolean consistentRead) Mapping template to query a set of items from a DynamoDB table.- Parameters:
cond
- the key condition for the query. This parameter is required.indexName
-consistentRead
-
-
dynamoDbQuery
@Stability(Stable) @NotNull public static MappingTemplate dynamoDbQuery(@NotNull KeyCondition cond, @Nullable String indexName) Mapping template to query a set of items from a DynamoDB table.- Parameters:
cond
- the key condition for the query. This parameter is required.indexName
-
-
dynamoDbQuery
Mapping template to query a set of items from a DynamoDB table.- Parameters:
cond
- the key condition for the query. This parameter is required.
-
dynamoDbResultItem
Mapping template for a single result item from DynamoDB. -
dynamoDbResultList
Mapping template for a result list from DynamoDB. -
dynamoDbScanTable
@Stability(Stable) @NotNull public static MappingTemplate dynamoDbScanTable(@Nullable Boolean consistentRead) Mapping template to scan a DynamoDB table to fetch all entries.- Parameters:
consistentRead
-
-
dynamoDbScanTable
Mapping template to scan a DynamoDB table to fetch all entries. -
fromFile
Create a mapping template from the given file.- Parameters:
fileName
- This parameter is required.
-
fromString
Create a mapping template from the given string.- Parameters:
template
- This parameter is required.
-
lambdaRequest
@Stability(Stable) @NotNull public static MappingTemplate lambdaRequest(@Nullable String payload, @Nullable String operation) Mapping template to invoke a Lambda function.- Parameters:
payload
- the VTL template snippet of the payload to send to the lambda.operation
- the type of operation AppSync should perform on the data source.
-
lambdaRequest
Mapping template to invoke a Lambda function.- Parameters:
payload
- the VTL template snippet of the payload to send to the lambda.
-
lambdaRequest
Mapping template to invoke a Lambda function. -
lambdaResult
Mapping template to return the Lambda result to the caller. -
renderTemplate
this is called to render the mapping template to a VTL string.
-