IAM凭证错误404

时间:2013-09-27 02:11:44

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

在us-east-1的ec2实例上运行,我无法获得boto使用IAM进行身份验证。 AMI是最近的亚马逊Linux。

$ python
Python 2.6.8 (unknown, Mar 14 2013, 09:31:22) 
[GCC 4.6.2 20111027 (Red Hat 4.6.2-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto
>>> boto.__version__
'2.13.3'
>>> c = boto.connect_s3()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/boto/__init__.py", line 135, in connect_s3
    return S3Connection(aws_access_key_id, aws_secret_access_key, **kwargs)
  File "/usr/lib/python2.6/site-packages/boto/s3/connection.py", line 174, in __init__
    validate_certs=validate_certs)
  File "/usr/lib/python2.6/site-packages/boto/connection.py", line 557, in __init__
    host, config, self.provider, self._required_auth_capability())
  File "/usr/lib/python2.6/site-packages/boto/auth.py", line 728, in get_auth_handler
    'Check your credentials' % (len(names), str(names)))
boto.exception.NoAuthHandlerFound: No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV1Handler'] Check your credentials

感谢https://github.com/boto/boto/pull/1175我能够获得更多信息。显然它正在尝试使用IAM,但失败了。

>>> import os
>>> boto.set_stream_logger('boto')
>>> c = boto.connect_s3()
2013-09-26 21:52:11,685 boto [DEBUG]:Retrieving credentials from metadata server.
2013-09-26 21:52:11,688 boto [ERROR]:Caught exception reading instance data
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/boto/utils.py", line 211, in retry_url
    r = opener.open(req)
  File "/usr/lib64/python2.6/urllib2.py", line 397, in open
    response = meth(req, response)
  File "/usr/lib64/python2.6/urllib2.py", line 510, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib64/python2.6/urllib2.py", line 435, in error
    return self._call_chain(*args)
  File "/usr/lib64/python2.6/urllib2.py", line 369, in _call_chain
    result = func(*args)
  File "/usr/lib64/python2.6/urllib2.py", line 518, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 404: Not Found
2013-09-26 21:52:11,725 boto [ERROR]:Unable to read instance data, giving up

快速tcpdump同意:boto与instance-data.ec2.internal连接到GET /latest/meta-data/iam/security-credentials/,然后接收404 Not Found。这似乎是第一个也是唯一的HTTP请求。到目前为止,我还没有找到任何类似问题的报告,但也许boto应该在GET请求路径的末尾提供角色名称?

任何人都能看到我做错了什么?我该如何调试此问题?

1 个答案:

答案 0 :(得分:2)

boto.exception.NoAuthHandlerFound: [...] Check your credentials

当您使用IAM时,您必须确保您拥有足够的S3权限,即将政策Amazon S3 Full Access附加到您的用户。