本文介绍了亚马逊DynamoDB - 地区特定的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Python中的博托库连接到DynamoDB。下面code一直为我工作就好了:

I'm using the boto library in Python to connect to DynamoDB. The following code has been working for me just fine:

import boto
key = 'abc'

secret = '123'
con = boto.connect_dynamodb(key,secret)
table = con.get_table('Table Name')
-- rest of code --

当我尝试连接到一个特定的区域,我可以连接得很好,但得到的表上工作是抛出一个错误:

When I try to connect to a specific region, I can connect just fine, but getting the table to work on is throwing an error:

import boto
from boto.ec2.connection import EC2Connection

key = 'abc'
secret = '123'
regions = EC2Connection(key,secret).get_all_regions() # some filtering after this line to remove unwanted entries
for r in regions:
  con = boto.connect_dynamodb(key,secret,region=r)
  table = con.get_table('Table Name') # throws the error below
  -- rest of code --

使用code以上的第二块,我收到了 ValueError错误:没有JSON对象可以去codeD 。呼叫 con.list_tables()显示我正在寻找在第一code块表,但会引发同样的错误,当我尝试在第二code座。谁能帮助我?

Using the second block of code above, I get a ValueError: No JSON object could be decoded. Calling con.list_tables() shows the table I'm looking for in the first code block, but throws the same error when I try it in the second code block. Can anyone help me out?

推荐答案

玩弄后,我发现改变code,以这种方式连接的工作原理:

After playing around, I found out that changing the code to connect in this fashion works:

import boto
from boto.ec2.connection import EC2Connection
from boto.dynamodb import connect_to_region

key = 'abc'
secret = '123'
regions = EC2Connection(key,secret).get_all_regions()
for r in regions:
  con = connect_to_region(aws_access_key_id=key,aws_secret_access_key=secret,region_name=r.name)
  table = con.get_table('Table Name') # no problem
  -- rest of code --

这篇关于亚马逊DynamoDB - 地区特定的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 02:48