HEX
Server: Apache
System: Linux vps-cdc32557.vps.ovh.ca 5.15.0-156-generic #166-Ubuntu SMP Sat Aug 9 00:02:46 UTC 2025 x86_64
User: hanode (1017)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //usr/lib/python3/dist-packages/awscli/examples/dynamodb/transact-write-items.rst
**Example 1: To write items atomically to one or more tables**

The 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. ::

    aws dynamodb transact-write-items \
        --transact-items file://transact-items.json \
        --return-consumed-capacity TOTAL \
        --return-item-collection-metrics SIZE

Contents of the ``transact-items.json`` file::

    [
        {
            "Update": {
                "Key": {
                    "Artist": {"S": "Acme Band"},
                    "SongTitle": {"S": "Happy Day"}
                },
                "UpdateExpression": "SET AlbumTitle = :newval",
                "ExpressionAttributeValues": {
                    ":newval": {"S": "Updated Album Title"}
                },
                "TableName": "MusicCollection",
                "ConditionExpression": "attribute_not_exists(Rating)"
            }
        },
        {
            "Delete": {
                "Key": {
                    "Artist": {"S": "No One You Know"},
                    "SongTitle": {"S": "Call Me Today"}
                },
                "TableName": "MusicCollection",
                "ConditionExpression": "attribute_not_exists(Rating)"
            }
        }
    ]

Output::

    {
        "ConsumedCapacity": [
            {
                "TableName": "MusicCollection",
                "CapacityUnits": 10.0,
                "WriteCapacityUnits": 10.0
            }
        ],
        "ItemCollectionMetrics": {
            "MusicCollection": [
                {
                    "ItemCollectionKey": {
                        "Artist": {
                            "S": "No One You Know"
                        }
                    },
                    "SizeEstimateRangeGB": [
                        0.0,
                        1.0
                    ]
                },
                {
                    "ItemCollectionKey": {
                        "Artist": {
                            "S": "Acme Band"
                        }
                    },
                    "SizeEstimateRangeGB": [
                        0.0,
                        1.0
                    ]
                }
            ]
        }
    }

For 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*.

**Example 2: To write items atomically using a client request token**

The 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. ::

    aws dynamodb transact-write-items \
        --transact-items file://transact-items.json \
        --client-request-token abc123

Contents of the ``transact-items.json`` file::

    [
        {
            "Update": {
                "Key": {
                    "Artist": {"S": "Acme Band"},
                    "SongTitle": {"S": "Happy Day"}
                },
                "UpdateExpression": "SET AlbumTitle = :newval",
                "ExpressionAttributeValues": {
                    ":newval": {"S": "Updated Album Title"}
                },
                "TableName": "MusicCollection",
                "ConditionExpression": "attribute_not_exists(Rating)"
            }
        },
        {
            "Delete": {
                "Key": {
                    "Artist": {"S": "No One You Know"},
                    "SongTitle": {"S": "Call Me Today"}
                },
                "TableName": "MusicCollection",
                "ConditionExpression": "attribute_not_exists(Rating)"
            }
        }
    ]

This command produces no output.

For 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*.