Skip to content

Instantly share code, notes, and snippets.

@Zerquix18
Created March 14, 2019 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zerquix18/b6ffd856411309e93a557da3e704d76d to your computer and use it in GitHub Desktop.
Save Zerquix18/b6ffd856411309e93a557da3e704d76d to your computer and use it in GitHub Desktop.
AWS AppSync resolver template to dynamically put stuff in a DynamoDB
{
"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