Amazon dynamodb DynamoDB的AWS AppSync解析器映射模板动态密钥
我正在尝试为DynamoDB'putItem'调用创建一个动态键。我拥有的当前(非动态)解析器映射模板是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}"
{
"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
希望这对将来的人有所帮助:)