我希望我的 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 中获取默认的“区域”。