https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/awscli/examples/dynamodb/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //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*.

https://t.me/RX1948 - 2025