Created
March 14, 2019 22:06
-
-
Save Zerquix18/b6ffd856411309e93a557da3e704d76d to your computer and use it in GitHub Desktop.
AWS AppSync resolver template to dynamically put stuff in a DynamoDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version" : "2017-02-28", | |
"operation" : "UpdateItem", | |
"key" : { | |
"id" : { "S" : "${ctx.args.id}" } | |
}, | |
#set( $expNames = {} ) | |
#set( $expValues = {} ) | |
#set( $expSet = {} ) | |
#foreach( $entry in $ctx.args.entrySet() ) | |
#if( $entry.key != "id") | |
$!{expSet.put("#${entry.key}", ":${entry.key}")} | |
$!{expNames.put("#${entry.key}", "$entry.key")} | |
$!{expValues.put(":${entry.key}", $util.dynamodb.toDynamoDB($entry.value))} | |
#end | |
#end | |
#set( $expression = "SET" ) | |
#foreach( $entry in $expSet.entrySet() ) | |
#set( $expression = "${expression} ${entry.key} = ${entry.value}" ) | |
#if ( $foreach.hasNext ) | |
#set( $expression = "${expression}," ) | |
#end | |
#end | |
"update" : { | |
"expression" : "${expression}", | |
"expressionNames" : $utils.toJson($expNames), | |
"expressionValues" : $utils.toJson($expValues), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment