An error occurred (TransactionCanceledException) when calling the TransactWriteItems operation: Transaction cancelled please refer cancellation reason

Viewed 123
for item in getSort["Items"]:
                    sortkey = item['History']['S']
                    params.append(
                                {
                                    'Update': {
                                        'TableName': 'vanguard-work-item-storage-history-db',
                                         'Key': {
                                            'Id': {
                                            'S': groupid
                                             },
                                            'Category': {
                                                'S': sortkey
                                            }
                                            },
                                        'UpdateExpression': 'set #stat = :val1',
                                        'ExpressionAttributeValues':{
                                            ':val1': {'N':str(int(epoch_value))}
                                        },
                                        'ExpressionAttributeNames': {
                                            '#stat': 'ttl'
                                        }
                                    }
                                }
                        )
dynamodb_client.transact_write_items(TransactItems=params)


exception-An error occurred (TransactionCanceledException) when calling the TransactWriteItems operation: Transaction cancelled, please refer cancellation reasons for specific reasons [ValidationError, None, None, 
None, None]

How to resolve the above exception. what may be the reason for it. I am adding multiple update items in one array and passing it to the transactwriteitems which is in for loop.

1 Answers

It's not possible to explain where the error is because the snippet does not seem to be complete.

What I can inferr from the error and the code is that you're appending an item to a list of items, and then trying to save them all in a single transaction.

The error occurs on the first item you're trying to insert. You can notice by looking at the list of errors in the message, the first entry reads ValidationError.

exception-An error occurred (TransactionCanceledException)
when calling the TransactWriteItems operation: Transaction cancelled,
please refer cancellation reasons for specific reasons 
[ValidationError, None, None, None, None]

Look on the first item of your transaction and ensure you're creating the Item following the AWS specs.

Related