I'm using $util.autoId()
and would like to know if there is a pattern to do an update_or_create()
(similar to the Django one) using VTL or if I should link the Resolver to a Lambda and do the logic in there?
Asked
Active
Viewed 1,419 times
3

Claudiordgz
- 3,023
- 1
- 21
- 48
-
What data source type are you using? – Rohan Deshpande Jun 20 '18 at 01:34
-
@RohanDeshpande DynamoDB Tables – Claudiordgz Jun 20 '18 at 03:32
2 Answers
2
You can use the Amazon DynamoDB UpdateItem operation to perform an update-else-create operation. We have published an end-to-end sample that includes an example AWS AppSync resolver that illustrates this pattern.

Rohan Deshpande
- 3,535
- 1
- 26
- 31
-
3I've read the tutorial on the resolver in the AWS docs, and there is nothing in the custom UpdateItem resolver that creates an item if that particular ID does not exist. Is this possible? I want to have a single API call that either creates (PutItem) or updates (UpdateItem) a new post, depending on whether the ID already exists. – protothe Jan 21 '19 at 18:50
-
1Was this ever resolved? When using Appsync's `update` function, I get `DynamoDB:ConditionalCheckFailedException` when trying to update a non-existent resource... the generated resolver does not appear to support create-or-update logic. – Kwhitejr Jul 08 '19 at 00:24
0
When creating a new resource in the AppSync console the following resolver is generated for the "updateYOUR_MODEL" mutation
just remove the last part:
"condition": {
"expression": "attribute_exists(#id)",
"expressionNames": {
"#id": "id",
},
}

Shai Volvovsky
- 123
- 1
- 10