1

I am migrating some code to use boto's DynamoDB2 libraries, but I am having trouble connecting with boot.dynamodb2. The original boto connections works fine, however.

I am using boto version 2.32.0 and python 2.7.3

import boto
import boto.dynamodb2
from boto.dynamodb2.table import Table

access_id = '-------------' # removed
secrey_key = '--------------' # removed

tablename = 'test'
lookup = 'hash1'

conn = boto.connect_dynamodb(aws_access_key_id=access_id, aws_secret_access_key=secret_key)
table1 = conn.get_table(tablename)
item1 = table1.get_item(lookup)
print "DB1 item :: ", item1

conn2 = boto.dynamodb2.connect_to_region('us-east-1', aws_access_key_id=access_id, aws_secret_access_key=secret_key)
table2 = Table(tablename)
item2 = table2.get_item(hashkey=lookup)
print "DB2 item :: ", item2

This is the output. Note that the item gets returned by the older dynamo call but not the boto.dynamodb2 version.

DB1 item ::  {'hashkey': 'hash1', 'value': 1}
Traceback (most recent call last):
  File "bototest.py", line 18, in <module>
    item2 = table2.get_item(hashkey=lookup)
  File "/usr/local/lib/python2.7/dist-packages/boto-2.31.0-py2.7.egg/boto/dynamodb2/table.py", line 502, in get_item
    consistent_read=consistent
  File "/usr/local/lib/python2.7/dist-packages/boto-2.31.0-py2.7.egg/boto/dynamodb2/layer1.py", line 911, in get_item
    body=json.dumps(params))
  File "/usr/local/lib/python2.7/dist-packages/boto-2.31.0-py2.7.egg/boto/dynamodb2/layer1.py", line 2100, in make_request
    retry_handler=self._retry_handler)
  File "/usr/local/lib/python2.7/dist-packages/boto-2.31.0-py2.7.egg/boto/connection.py", line 940, in _mexe
    status = retry_handler(response, i, next_sleep)
  File "/usr/local/lib/python2.7/dist-packages/boto-2.31.0-py2.7.egg/boto/dynamodb2/layer1.py", line 2143, in _retry_handler
    data)
boto.exception.JSONResponseError: JSONResponseError: 400 Bad Request
{u'message': u'The security token included in the request is invalid.', u'__type': u'com.amazon.coral.service#UnrecognizedClientException'}

1 Answer 1

3

You have to provide the connection when creating the table object:

table2 = Table(tablename, connection=conn2)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I should have noticed something so obvious. I've been staring at the official boto migration docs completely baffled. Unfortunately, they leave out many of the connection steps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.