我正在运行本地dockerised DynamoDB:
~ docker run -d -p 8000:8000 amazon/dynamodb-local
...其中有一个表,通过aws dynamodb CLI *创建。
从ipython shell boto3可以找到没有问题的表:
db = boto3.resource('dynamodb',
endpoint_url='http://localhost:8000',
region_name='eu-west-2')
print([t for t in db.tables.all()])
# ==> [dynamodb.Table(name=u'myTable')]
...但是当从本地运行的flask应用程序中的断点访问此表时,boto3找不到该表:
db = boto3.resource('dynamodb',
endpoint_url='http://localhost:8000',
region_name='eu-west-2')
[t for t in db.tables.all()]
# ==> []
我想不出任何关于烧瓶应用的上下文会改变boto3的工作方式,所以我有点卡住了。为什么在两种情况下对db.tables.all()
的调用都不一样?
两个上下文都使用boto v1.7.1和python 2.7.13从相同的virtualenv运行
*用于创建表的CLI命令:
~ aws dynamodb create-table --table-name myTable --attribute-definitions AttributeName=api_key,AttributeType=S AttributeName=session_id,AttributeType=S AttributeName=time_stamp,AttributeType=N --key-schema AttributeName=session_id,KeyType=HASH --global-secondary-indexes IndexName=api_key-time_stamp-index,KeySchema=["{KeyType=HASH,AttributeName=api_key}","{KeyType=RANGE,AttributeName=time_stamp}"],Projection="{ProjectionType=ALL}",ProvisionedThroughput="{ReadCapacityUnits=5,WriteCapacityUnits=5}" --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 --endpoint-url http://localhost:8000 --region eu-west-2
弄清楚了。问题是我在运行烧瓶应用程序时在我的环境变量中有我的AWS_ACCESS_KEY_ID
和AWS_SECRET_ACCESS_KEY
。我知道boto3 automatically checks for the presence of these在使用时,但我没有意识到这会对本地DynamoDB产生任何影响。如果没有深入研究源代码,看起来它有效地将本地DynamoDB划分为每个AWS_ACCESS_KEY_ID
的不同实例,包括未设置AWS_ACCESS_KEY_ID
的情况。