【问题标题】:Amazon DynamoDB -- region-specific connectionAmazon DynamoDB -- 特定于区域的连接
【发布时间】:2012-06-21 12:08:22
【问题描述】:

我在 Python 中使用 boto 库连接到 DynamoDB。以下代码对我来说效果很好:

import boto
key = 'abc'

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

当我尝试连接到特定区域时,我可以正常连接,但是让表工作会引发错误:

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 --

使用上面的第二个代码块,我得到一个ValueError: No JSON object could be decoded。调用 con.list_tables() 会显示我在第一个代码块中查找的表,但是当我在第二个代码块中尝试它时会引发相同的错误。谁能帮帮我?

【问题讨论】:

    标签: python amazon-web-services amazon-dynamodb boto


    【解决方案1】:

    玩了一圈后,我发现以这种方式更改代码以进行连接是可行的:

    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 --
    

    【讨论】:

      猜你喜欢
      • 2021-11-12
      • 1970-01-01
      • 2014-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-20
      相关资源
      最近更新 更多