I want the following table structure, to store an auto increment a row's pid* attribute
| id | timstamp | pid*
| 00000000-1111-2222-93bb-0371fcb45674 | 0 | 1
| 00000000-1111-2222-93bb-ee742a825e88 | 1 | 2
| 00000000-1111-2222-93bb-bfac8753c0ba | 2 | 3
PutItem -> autoId() | timestamp() | max(pid) + 1 = 4 ??
For PutItem operation, Is something like the following 1) possible, and 2) acceptable in DynamoDB land?
"pid" : $util.dynamodb.toDynamoDBJson(records.findMax(pid) + 1) # just pseudo code
3) How might one implement the above using DyanmoDB resolver mapper template?
Use case:
I'm trying to use AWS DynamoDB to back GraphQL, managed by AWS AppSync, the following is the request mapping template for Mutation.createFoo
{
"version" : "2018-05-29",
"operation" : "PutItem",
"key" : {
"id": $util.dynamodb.toDynamoDBJson($util.autoId()),
},
"attributeValues" : {
"timestamp" : $util.dynamodb.toDynamoDBJson($util.time.nowEpochMilliSeconds()),
"pid" : $util.dynamodb.toDynamoDBJson($ctx.args.input.pid), # currently client provided but it is not acceptable
...
}
}
The primary key id is an UUID auto-generated by DynamoDB which is fine. But our use-case requires a incrementing pid for each new Foo in our FooTable. The business model requires at least for show a unique pid, while under the hood, queries like GetItem the UUID and timestamp will be used instead and business as usual.
I'm also weary to call for a change in business model because of an implementation detail issue.
References: