Python 与DynamoDB2的连接错误,但与使用boto的DynamoDB的连接错误

Python 与DynamoDB2的连接错误,但与使用boto的DynamoDB的连接错误,python,python-2.7,boto,amazon-dynamodb,Python,Python 2.7,Boto,Amazon Dynamodb,我正在迁移一些代码以使用boto的DynamoDB2库,但在连接boot.DynamoDB2时遇到问题。然而,原始的boto连接工作正常 我使用的是boto版本2.32.0和python 2.7.3 import boto import boto.dynamodb2 from boto.dynamodb2.table import Table access_id = '-------------' # removed secrey_key = '--------------' # remove

我正在迁移一些代码以使用boto的DynamoDB2库,但在连接boot.DynamoDB2时遇到问题。然而,原始的boto连接工作正常

我使用的是boto版本2.32.0和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
这是输出。请注意,该项由较旧的dynamo调用返回,但不是由boto.dynamodb2版本返回

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'}
DB1项::{'hashkey':'hash1','value':1}
回溯(最近一次呼叫最后一次):
文件“bototest.py”,第18行,在
item2=table2.get_项(hashkey=lookup)
文件“/usr/local/lib/python2.7/dist packages/boto-2.31.0-py2.7.egg/boto/dynamodb2/table.py”,第502行,在get_项中
一致的,一致的
文件“/usr/local/lib/python2.7/dist packages/boto-2.31.0-py2.7.egg/boto/dynamodb2/layer1.py”,第911行,在get\u项中
body=json.dumps(参数))
文件“/usr/local/lib/python2.7/dist packages/boto-2.31.0-py2.7.egg/boto/dynamodb2/layer1.py”,第2100行,在make_请求中
retry\u handler=self.\u retry\u handler)
文件“/usr/local/lib/python2.7/dist-packages/boto-2.31.0-py2.7.egg/boto/connection.py”,第940行,in_-mexe
状态=重试\u处理程序(响应、i、下一个\u睡眠)
文件“/usr/local/lib/python2.7/dist packages/boto-2.31.0-py2.7.egg/boto/dynamodb2/layer1.py”,第2143行,在“重试”处理程序中
(数据)
boto.exception.JSONResponseError:JSONResponseError:400错误请求
{u'message':u'请求中包含的安全令牌无效。“,u''u类型]:u'com.amazon.coral.service#UnrecognizedClientException'}

创建表对象时必须提供连接:

table2 = Table(tablename, connection=conn2)

非常感谢。我应该注意到一些如此明显的事情。我一直盯着官方的boto迁移文档,完全不知所措。不幸的是,它们遗漏了许多连接步骤。