【发布时间】:2017-02-15 11:20:11
【问题描述】:
我一直在尝试连接到 Amazon 的 boto SDK 以构建连接到 Amazon 的 MWS 服务的连接器。
但是,现在,我能够向 boto.mws.connection 的 MWSConnection 类提供我的凭据的唯一方法是硬编码访问密钥和密钥。显然这不适合部署。
当我使用 SQS 等其他 Amazon 服务时,我已经能够使用 IAM 角色和配置文件进行连接。例如,下面是一些我用来通过配置文件连接到 SQS 的示例代码:
REGION = "us-west-2"
PROFILE_NAME = 'my_profile'
class SQSManager(object):
def __init__(self):
self.conn = boto.sqs.connect_to_region(region_name=REGION, profile_name=PROFILE_NAME)
但是,我还没有找到通过 MWS 的 profile_name 进行连接的方法。我搜索了 MWSConnection 类的方法,这就是它实例化连接的方式:
class MWSConnection(AWSQueryConnection):
ResponseFactory = boto.mws.response.ResponseFactory
ResponseErrorFactory = boto.mws.exception.ResponseErrorFactory
def __init__(self, *args, **kw):
kw.setdefault('host', 'mws.amazonservices.com')
self._sandboxed = kw.pop('sandbox', False)
self.Merchant = kw.pop('Merchant', None) or kw.get('SellerId')
self.SellerId = kw.pop('SellerId', None) or self.Merchant
kw = self._setup_factories(kw.pop('factory_scopes', []), **kw)
super(MWSConnection, self).__init__(*args, **kw)
它显然接受访问/密钥是关键字参数。无论如何使用配置文件和 IAM 角色使用 Amazon 的 boto SDK 连接到 MWS?
【问题讨论】:
标签: python-2.7 amazon-web-services boto