Noah Shay
Noah Shay

Reputation: 44

Cannot add an item to a new DynamoDB table

I need to move an item from one DynamoDb table to another DynamoDB table. When I use the put_item () function I get an error: <class 'AttributeError'> Object 'dynamodb.ServiceResource' does not have attribute 'put_item'

table = dynamodb.Table ('table1')
newTable = dynamodb.Table('table2')

It's the connection to my tables - the connection is successful I read an item from Table 1 and put data in and sent it to the following function:

    try:
        dynamodb.put_item(newTable,data)
        return data
    except:
        e, p, t = sys.exc_info ()
        print ("test")
        print (e, p)

Upvotes: 0

Views: 785

Answers (1)

Marcin
Marcin

Reputation: 238965

Instead of dynamodb.put_item(newTable,data) use:

newTable.put_item(data)

In your context, put_item is a method of Table object.

Upvotes: 2

Related Questions