AWS DynamoDB snippets

How to put (insert) data to DynamoDB with Python boto3

Please note that this snippet is part of the DynamoDB-Simpsons-episodes-full-example repository on GitHub.

Let's say you want to insert an item to a DynamoDB table.


First of all, you have to create a Resource (follow these steps) and then you can use the following code to assign a value to the variables used below.

table = dynamodbRes.Table(TABLENAME)

    response = table.put_item(
            'No_Season': 99,
            'No_Inseason': 1,
            'Title':'Best episode ever!'
{'ResponseMetadata': {'RequestId': '92HH7P4B4QNTIVBHPG02HGE827VV4KQNSO5AEMVJF66Q9ASUAAJG',
    'HTTPStatusCode': 200,
    'HTTPHeaders': {'server': 'Server',
     'date': 'Wed, 07 Dec 2022 16:23:12 GMT',
     'content-type': 'application/x-amz-json-1.0',
     'content-length': '2',
     'connection': 'keep-alive',
     'x-amzn-requestid': '92HH7P4B4QNTIVBHPG02HGE827VV4KQNSO5AEMVJF66Q9ASUAAJG',
     'x-amz-crc32': '2745614147'},
    'RetryAttempts': 0}}

Back to AWS DynamoDB cookbook page