Idempotence is a property of an operation (transaction) whereby they can be applied multiple times without changing the result beyond the initial application.
TransactWriteItems api has a parameter that can be used for making this API’s behavior idempotent. The name of the parameter is ClientToken.
Client Token is valid for 10 minutes i.e., the if token is re-used within 10 minutes the behavior of the TransactWriteItems will be idempotent but if the same token is used after 10 minutes, the token will be treated as a new token/transaction and the operations will be executed.
As you can see wit th euse of ClientToken, TransactWriteItems API is behaving like an idempotent operation.
aws dynamodb transact-write-items \
--client-request-token 12345, \
--transact-items '[
{
"Update": {
"TableName": "FlashSaleDiscounts",
"Key": {
"PK": {"S":"CUST#john"},
"SK": {"S":"CUST#john"}
},
"UpdateExpression": "SET #LoyaltyPoints = #LoyaltyPoints + :LoyaltyPoints",
"ExpressionAttributeNames": {"#LoyaltyPoints":"LoyaltyPoints"},
"ExpressionAttributeValues": {":LoyaltyPoints": {"N":"500"}}
}
}
]' \
--endpoint-url http://localhost:8000