1**Example 1: To write items atomically to one or more tables** 2 3The following ``transact-write-items`` example updates one item and deletes another. The operation fails if either operation fails, or if either item contains a ``Rating`` attribute. :: 4 5 aws dynamodb transact-write-items \ 6 --transact-items file://transact-items.json \ 7 --return-consumed-capacity TOTAL \ 8 --return-item-collection-metrics SIZE 9 10Contents of the ``transact-items.json`` file:: 11 12 [ 13 { 14 "Update": { 15 "Key": { 16 "Artist": {"S": "Acme Band"}, 17 "SongTitle": {"S": "Happy Day"} 18 }, 19 "UpdateExpression": "SET AlbumTitle = :newval", 20 "ExpressionAttributeValues": { 21 ":newval": {"S": "Updated Album Title"} 22 }, 23 "TableName": "MusicCollection", 24 "ConditionExpression": "attribute_not_exists(Rating)" 25 } 26 }, 27 { 28 "Delete": { 29 "Key": { 30 "Artist": {"S": "No One You Know"}, 31 "SongTitle": {"S": "Call Me Today"} 32 }, 33 "TableName": "MusicCollection", 34 "ConditionExpression": "attribute_not_exists(Rating)" 35 } 36 } 37 ] 38 39Output:: 40 41 { 42 "ConsumedCapacity": [ 43 { 44 "TableName": "MusicCollection", 45 "CapacityUnits": 10.0, 46 "WriteCapacityUnits": 10.0 47 } 48 ], 49 "ItemCollectionMetrics": { 50 "MusicCollection": [ 51 { 52 "ItemCollectionKey": { 53 "Artist": { 54 "S": "No One You Know" 55 } 56 }, 57 "SizeEstimateRangeGB": [ 58 0.0, 59 1.0 60 ] 61 }, 62 { 63 "ItemCollectionKey": { 64 "Artist": { 65 "S": "Acme Band" 66 } 67 }, 68 "SizeEstimateRangeGB": [ 69 0.0, 70 1.0 71 ] 72 } 73 ] 74 } 75 } 76 77For more information, see `Managing Complex Workflows with DynamoDB Transactions <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/transactions.html>`__ in the *Amazon DynamoDB Developer Guide*. 78 79**Example 2: To write items atomically using a client request token** 80 81The following command uses a client request token to make the call to ``transact-write-items`` idempotent, meaning that multiple calls have the same effect as one single call. :: 82 83 aws dynamodb transact-write-items \ 84 --transact-items file://transact-items.json \ 85 --client-request-token abc123 86 87Contents of the ``transact-items.json`` file:: 88 89 [ 90 { 91 "Update": { 92 "Key": { 93 "Artist": {"S": "Acme Band"}, 94 "SongTitle": {"S": "Happy Day"} 95 }, 96 "UpdateExpression": "SET AlbumTitle = :newval", 97 "ExpressionAttributeValues": { 98 ":newval": {"S": "Updated Album Title"} 99 }, 100 "TableName": "MusicCollection", 101 "ConditionExpression": "attribute_not_exists(Rating)" 102 } 103 }, 104 { 105 "Delete": { 106 "Key": { 107 "Artist": {"S": "No One You Know"}, 108 "SongTitle": {"S": "Call Me Today"} 109 }, 110 "TableName": "MusicCollection", 111 "ConditionExpression": "attribute_not_exists(Rating)" 112 } 113 } 114 ] 115 116This command produces no output. 117 118For more information, see `Managing Complex Workflows with DynamoDB Transactions <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/transactions.html>`__ in the *Amazon DynamoDB Developer Guide*.