【发布时间】:2015-07-31 13:22:28
【问题描述】:
我希望我的 python 脚本(连接到 aws)使用来自 ~/.aws/credentials 的 aws 配置文件
所以,我有 ~/.aws/credentials 文件:
[default]
aws_access_key_id = XXX
aws_secret_access_key = AAA
region = eu-west-1
[test]
aws_access_key_id = WWW
aws_secret_access_key = ZZZ
region = eu-west-1
我的python代码
import boto.ec2
conn = boto.ec2.EC2Connection(profile_name='test')
print conn
print conn.get_all_instances()
输出是
EC2Connection:ec2.us-east-1.amazonaws.com
[]
所以,它似乎没有从配置中获取配置文件。地区错了。
env | grep -i aws <- returns nothing
我错过了什么?
谢谢。
===== 更新 =====
我也有一个 ~/.aws/config 文件,看起来像
⟩ cat config
[default]
output = text
region = eu-west-1
[profile test]
output = text
region = eu-west-1
===== 更新 =====
显然,它需要连接详细信息.. 但不是区域。所以,如果我这样做了
reg = next(x for x in boto.ec2.regions() if x.name=='eu-west-1')
conn = boto.ec2.EC2Connection(profile_name='test', region=reg)
print conn
print conn.get_all_instances()
我可以获得实例列表。
所以,问题是如何从 AWS config/credentials 中获取默认的“区域”。
【问题讨论】:
-
我注意到了同样的问题。我很好奇是否存在解决方案。
标签: python amazon-web-services amazon-ec2 boto aws-ec2