Skip to content

Instantly share code, notes, and snippets.

@koingdev
Created July 22, 2019 09:33
Show Gist options
  • Save koingdev/69d0f27d0c98bc3f897a0f777dcd6d44 to your computer and use it in GitHub Desktop.
Save koingdev/69d0f27d0c98bc3f897a0f777dcd6d44 to your computer and use it in GitHub Desktop.
Sample AppSync Resolver for PutItem Operation including with Conflict Resolution
{
"version" : "2017-02-28",
"operation" : "PutItem",
"key" : {
"shopID" : $util.dynamodb.toDynamoDBJson($ctx.args.shopID),
"id": $util.dynamodb.toDynamoDBJson($ctx.args.id)
},
"attributeValues" : {
"staffName" : $util.dynamodb.toDynamoDBJson($ctx.args.staffName),
"modifiedDate": $util.dynamodb.toDynamoDBJson($ctx.args.modifiedDate),
"createdDate": $util.dynamodb.toDynamoDBJson($ctx.args.createdDate)
},
## Conflict Resolution with modified date
"condition" : {
## If old modifiedDate smaller than new modifiedDate ==> okay
## Else ==> error (Not Latest version)
"expression" : "modifiedDate < :modifiedDate",
"expressionValues" : {
":modifiedDate" : $util.dynamodb.toDynamoDBJson($ctx.args.modifiedDate)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment