aws-appsync-community
aws-appsync-community copied to clipboard
Runtime Error with transactWriteItems in AppSync JS Runtime on DynamoDB Versioned Data Source
I am experiencing a runtime error when using the transactWriteItems operation in the AppSync JavaScript runtime, specifically with a DynamoDB data source that has the versioning feature enabled. The same code operates correctly on a data source where versioning is not enabled.
Interestingly, the transactGetItems operation functions as expected in both environments. This makes sense as the GetItem operation is not affected by the versioning feature.
I have not found any documentation stating that the transactWriteItems operation is incompatible with versioned DynamoDB data sources. Therefore, I am reporting this issue for further investigation.
Steps to Reproduce
- example appsync schema:
type Mutation {
test(t: String): Boolean
}
schema {
mutation: Mutation
}
- example resolver function:
export function request(ctx) {
const { t } = ctx.args;
return {
version: '2018-05-29',
operation: 'TransactWriteItems',
transactItems: [{
table: 'test',
operation: 'PutItem',
key: util.dynamodb.toMapValues({ pk: "a", sk: "b"}),
attributeValues: util.dynamodb.toMapValues({ hello: "world!", text: t }),
}, {
table: 'test',
operation: 'PutItem',
key: util.dynamodb.toMapValues({ pk: "a", sk: "c"}),
attributeValues: util.dynamodb.toMapValues({ hello: "world!", text: t }),
}],
};
}
export function response(ctx) {
console.log(ctx.result);
return true;
}
- query
mutation Test {
test(t: "Hello")
}
- error:
{
"data": {
"test": null
},
"errors": [
{
"path": [
"test"
],
"data": null,
"errorType": "Code",
"errorInfo": null,
"locations": [
{
"line": 64,
"column": 3,
"sourceName": null
}
],
"message": "Runtime Error"
}
]
}
Also seeing this behavior with a TransactWriteItems
call I'm attempting to make. One of the transaction items is a GetItem, but the other is a PutItem. Error I'm seeing has nothing helpful, just that it's a Runtime error:
[
{
"path": ["<myPath>"],
"data":null,
"errorType":"Code",
"errorInfo":null,
"locations": [{"line":3,"column":13,"sourceName":null}],
"message":"Runtime Error"
}
]
In my case however, ~I don't believe my Dynamo table has versioning enabled~ I confirmed that my DDB data source does not have versioning enabled. 🤔
I had the same issue also. It turns out I was missing returnValuesOnConditionCheckFailure
This works for me:
import { AppSyncIdentityCognito, Context, DynamoDBTransactWriteItemsRequest, } from "@aws-appsync/utils";
export function request(ctx: Context
return transactionWriteItems; }
export const response = (ctx: Context) => { if (ctx.error) { util.error(ctx.error.message, ctx.error.type); }
return true; };