. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . AnonSec Shell
AnonSec Shell
Server IP : 52.223.31.75  /  Your IP : 172.31.32.98   [ Reverse IP ]
Web Server : Apache/2.4.66 () OpenSSL/1.0.2k-fips PHP/7.4.33
System : Linux ip-172-31-14-81.eu-central-1.compute.internal 4.14.281-212.502.amzn2.x86_64 #1 SMP Thu May 26 09:52:17 UTC 2022 x86_64
User : apache ( 48)
PHP Version : 7.4.33
Disable Function : NONE
Domains : 4 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python2.7/site-packages/awscli/examples/dynamodb/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python2.7/site-packages/awscli/examples/dynamodb/update-item.rst
**Example 1: To update an item in a table**

The following ``update-item`` example updates an item in the ``MusicCollection`` table. It adds a new attribute (``Year``) and modifies the ``AlbumTitle`` attribute. All of the attributes in the item, as they appear after the update, are returned in the response. ::

    aws dynamodb update-item \
        --table-name MusicCollection \
        --key file://key.json \
        --update-expression "SET #Y = :y, #AT = :t" \
        --expression-attribute-names file://expression-attribute-names.json \
        --expression-attribute-values file://expression-attribute-values.json  \
        --return-values ALL_NEW \
        --return-consumed-capacity TOTAL \
        --return-item-collection-metrics SIZE

Contents of ``key.json``::

    {
        "Artist": {"S": "Acme Band"},
        "SongTitle": {"S": "Happy Day"}
    }

Contents of ``expression-attribute-names.json``::

    {
        "#Y":"Year", "#AT":"AlbumTitle"
    }

Contents of ``expression-attribute-values.json``::

    {
        ":y":{"N": "2015"},
        ":t":{"S": "Louder Than Ever"}
    }

Output::

    {
        "Attributes": {
            "AlbumTitle": {
                "S": "Louder Than Ever"
            },
            "Awards": {
                "N": "10"
            },
            "Artist": {
                "S": "Acme Band"
            },
            "Year": {
                "N": "2015"
            },
            "SongTitle": {
                "S": "Happy Day"
            }
        },
        "ConsumedCapacity": {
            "TableName": "MusicCollection",
            "CapacityUnits": 3.0
        },
        "ItemCollectionMetrics": {
            "ItemCollectionKey": {
                "Artist": {
                    "S": "Acme Band"
                }
            },
            "SizeEstimateRangeGB": [
                0.0,
                1.0
            ]
        }
    }

For more information, see `Writing an Item <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html#WorkingWithItems.WritingData>`__ in the *Amazon DynamoDB Developer Guide*.

**Example 2: To update an item conditionally**

The following example updates an item in the ``MusicCollection`` table, but only if the existing item does not already have a ``Year`` attribute.

    aws dynamodb update-item \
        --table-name MusicCollection \
        --key file://key.json \
        --update-expression "SET #Y = :y, #AT = :t" \
        --expression-attribute-names file://expression-attribute-names.json \
        --expression-attribute-values file://expression-attribute-values.json  \
        --condition-expression "attribute_not_exists(#Y)"

Contents of ``key.json``::

    {
        "Artist": {"S": "Acme Band"},
        "SongTitle": {"S": "Happy Day"}
    }

Contents of ``expression-attribute-names.json``::

    {
        "#Y":"Year",
        "#AT":"AlbumTitle"
    }

Contents of ``expression-attribute-values.json``::

    {
        ":y":{"N": "2015"},
        ":t":{"S": "Louder Than Ever"}
    }

If the item already has a ``Year`` attribute, DynamoDB returns the following output::

    An error occurred (ConditionalCheckFailedException) when calling the UpdateItem operation: The conditional request failed

For more information, see `Writing an Item <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html#WorkingWithItems.WritingData>`__ in the *Amazon DynamoDB Developer Guide*.

Anon7 - 2022
AnonSec Team