HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
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: //lib/python3/dist-packages/awscli/examples/dynamodb/put-item.rst
**Example1: To add an item to a table**

The following ``put-item`` example adds a new item to the *MusicCollection* table. ::

    aws dynamodb put-item \
        --table-name MusicCollection \
        --item file://item.json \
        --return-consumed-capacity TOTAL

Contents of ``item.json``::

    {
        "Artist": {"S": "No One You Know"},
        "SongTitle": {"S": "Call Me Today"},
        "AlbumTitle": {"S": "Somewhat Famous"}
    }

Output::

    {
        "ConsumedCapacity": {
            "CapacityUnits": 1.0,
            "TableName": "MusicCollection"
        }
    }

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

**Example2: To add an item to a table conditionally**

The following ``put-item`` example adds a new item to the ``MusicCollection`` table only if the artist "Obscure Indie Band" does not already exist in the table. ::

    aws dynamodb put-item \
        --table-name MusicCollection \
        --item '{"Artist": {"S": "Obscure Indie Band"}}' \
        --condition-expression "attribute_not_exists(Artist)"

If the key already exists, you should see the following output::

    A client error (ConditionalCheckFailedException) occurred when calling the PutItem operation: The conditional request failed.

For more information, see `Condition Expressions <https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ConditionExpressions.html>`__ in the *Amazon DynamoDB Developer Guide*.