我正在尝试使用Ansible的./ec2.py --list --refresh-cache来列出我的AWS EC2实例。
通过文档,我已经通过这个清单:
pip和boto aws_access_key_id和aws_secret_access_key的~/.boto文件,我从AWS IAM用户的访问凭证 ec2.py和ec2.ini安装到相同的path,并保持两个文件不变 ./ec2.py --list --refresh-cache *我的政策:
{ "Statement": [ { "Sid": "Stmt1427001800780", "Action": "*", "Effect": "Allow", "Resource": "*" } ] }
我这样做,并期望能够通过ec2.py列出的EC2实例本质上通过boto路由,但实际上看到Error connecting to AWS backend. You are not authorized to perform this operation Error connecting to AWS backend. You are not authorized to perform this operation 。 然而,我可以通过ssh ubuntu@[ip]直接ssh入我的EC2实例。
我真的在这里撞墙了。 我究竟做错了什么?
编辑:根据@ EEAA的build议添加一些新的信息
当我在亚马逊的响应中使用pprint.pprint(e)时:
EC2ResponseError: 403 Forbidden <?xml version="1.0" encoding="UTF-8"?> <Response><Errors><Error><Code>UnauthorizedOperation</Code><Message>You are not authorized to perform this operation.</Message></Error></Errors><RequestID>b985d559-c410-4462-8b10-e0819fd81f12</RequestID></Response>
我的~/.botoconfiguration如下:
[Credentials] aws_access_key_id = removed aws_secret_access_key = removed
作为对“./ec2.py –list”的回应,我得到了“禁止”。 它看起来像一个错误,当不使用RDS和一个查询请求来描述RDS资源(这是该插件的默认值)。 只需在ec2.ini中禁用这样的请求即可:
rds = False
如果不使用ElasticCache,则必须将其设置为False。 所以取消注释
elasticache = False
我发现有必要将IAM用户和组附加到AmazonEC2FullAccess策略(或任何其他带有ec2:Describe*操作的策略,以允许从Ansible列出实例)。
当然,还需要将elasticcache和rdsconfiguration标志设置为false的其他答案,否则我会获得以下响应: ERROR: "Forbidden", while: getting RDS instances或ERROR: "Forbidden", while: getting ElastiCache clusters 。