Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon dynamodb DynamoDB的AWS AppSync解析器映射模板动态密钥_Amazon Dynamodb_Velocity_Aws Appsync - Fatal编程技术网

Amazon dynamodb DynamoDB的AWS AppSync解析器映射模板动态密钥

Amazon dynamodb DynamoDB的AWS AppSync解析器映射模板动态密钥,amazon-dynamodb,velocity,aws-appsync,Amazon Dynamodb,Velocity,Aws Appsync,我正在尝试为DynamoDB'putItem'调用创建一个动态键。我拥有的当前(非动态)解析器映射模板是 { "version" : "2017-02-28", "operation" : "PutItem", "key" : { "userId1" : { "S" : "${context.identity.sub}"

我正在尝试为DynamoDB'putItem'调用创建一个动态键。我拥有的当前(非动态)解析器映射模板是

{
  "version" : "2017-02-28",
  "operation" : "PutItem",
  "key" : {
    "userId1" : { "S" : "${context.identity.sub}" },
    "userId2" : { "S" : "${context.stash.userId2}" },
  },
  "attributeValues" : {
   ...
  }
}
我正在尝试使关键部分动态化,我尝试过的其中一个不起作用的尝试是:

{
  "version" : "2017-02-28",
  "operation" : "PutItem",
  #set($key={})
  #set($keyValue1={})
  #set($keyValue2={})
  $keyValue1.put("S", ${context.identity.sub})
  $keyValue2.put("S", ${context.stash.userId2})
  $util.qr($key.put("userId1", $keyValue1))
  $util.qr($key.put("userId2", $keyValue2))

  "key" : $util.toJson($key),
  "attributeValues" : {
    ...
  }
}
对于这类事情,我在文档中看不到太多。任何指点都将不胜感激


谢谢

我找到了一个解决方案,希望与大家分享

    "version" : "2017-02-28",
    "operation" : "PutItem",

    #set($key={})

    #set($key.userId1= $util.dynamodb.toString("${context.identity.sub}"))

    #if(!$ctx.prev.result.items.isEmpty()) ## My condition is based on result from previous template
      #set($key.userId2 = $util.dynamodb.toString("${ctx.prev.result.items[0].userId}"))
    #else
      #set($key.userId2 = $util.dynamodb.toString("${context.stash.anotherValue}"))
    #end

    "key" : $util.toJson($key), ## convert map/object to JSON and set the 'key' for use in the DynamoDB request

希望这对将来的人有所帮助:)

我找到了一个解决方案,希望与大家分享

    "version" : "2017-02-28",
    "operation" : "PutItem",

    #set($key={})

    #set($key.userId1= $util.dynamodb.toString("${context.identity.sub}"))

    #if(!$ctx.prev.result.items.isEmpty()) ## My condition is based on result from previous template
      #set($key.userId2 = $util.dynamodb.toString("${ctx.prev.result.items[0].userId}"))
    #else
      #set($key.userId2 = $util.dynamodb.toString("${context.stash.anotherValue}"))
    #end

    "key" : $util.toJson($key), ## convert map/object to JSON and set the 'key' for use in the DynamoDB request
希望这对将来的人有所帮助:)