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.101.0 (build b95fe5d)", date="2024-07-12T19:33:57.721Z") @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());
 
  • 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

      @Stability(Stable) @NotNull public static MappingTemplate dynamoDbQuery(@NotNull KeyCondition cond)
      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

      @Stability(Stable) @NotNull public static MappingTemplate dynamoDbResultItem()
      Mapping template for a single result item from DynamoDB.
    • dynamoDbResultList

      @Stability(Stable) @NotNull public static MappingTemplate 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

      @Stability(Stable) @NotNull public static MappingTemplate dynamoDbScanTable()
      Mapping template to scan a DynamoDB table to fetch all entries.
    • fromFile

      @Stability(Stable) @NotNull public static MappingTemplate fromFile(@NotNull String fileName)
      Create a mapping template from the given file.

      Parameters:
      fileName - This parameter is required.
    • fromString

      @Stability(Stable) @NotNull public static MappingTemplate fromString(@NotNull String template)
      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

      @Stability(Stable) @NotNull public static MappingTemplate lambdaRequest(@Nullable String payload)
      Mapping template to invoke a Lambda function.

      Parameters:
      payload - the VTL template snippet of the payload to send to the lambda.
    • lambdaRequest

      @Stability(Stable) @NotNull public static MappingTemplate lambdaRequest()
      Mapping template to invoke a Lambda function.
    • lambdaResult

      @Stability(Stable) @NotNull public static MappingTemplate lambdaResult()
      Mapping template to return the Lambda result to the caller.
    • renderTemplate

      @Stability(Stable) @NotNull public abstract String renderTemplate()
      this is called to render the mapping template to a VTL string.