gpt4 book ai didi

python - AutoScaleConnection.get_all_groups() 不适用于 boto

转载 作者:行者123 更新时间:2023-12-01 04:46:49 24 4
gpt4 key购买 nike

我尝试连接到 aws autoscale 并获取所有组。我收到以下错误:

from boto import ec2
from boto.ec2.autoscale import AutoScaleConnection
import boto
AWS_ACCESS_KEY = "<key>"
AWS_SECRET_KEY = "secret"
REGION = 'us-west-1'
region_info = boto.ec2.get_region('us-west-1')

conn = AutoScaleConnection(aws_access_key_id=AWS_ACCESS_KEY, aws_secret_access_key=AWS_SECRET_KEY, region=region_info)

conn.get_all_groups()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/boto/ec2/autoscale/__init__.py", line 342, in get_all_groups
[('member', AutoScalingGroup)])
File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 1185, in get_list
raise self.ResponseError(response.status, response.reason, body)
boto.exception.BotoServerError: BotoServerError: 400 Bad Request
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>InvalidAction</Code><Message>The action DescribeAutoScalingGroups is not valid for this web service.</Message></Error></Errors><RequestID>sadsdasdsdsdsadasdasd</RequestID></Response>

我尝试了另一种方法:这有效

conn = boto.ec2.autoscale.connect_to_region('us-west-1')
conn.get_all_groups()

但我不想使用 boto 存储的默认配置文件。我想提供访问 key 等作为参数(如上面的示例中尝试的那样)

感谢任何帮助。

我正在关注本教程:http://boto.readthedocs.org/en/latest/autoscale_tut.html

最佳答案

您仍然可以将显式凭据传递给 connect_to_region 方法,如下所示:

import boto.ec2.autoscale
conn = boto.ec2.autoscale.connect_to_region('us-west-2', aws_access_key_id='YOUR_ACCESS_KEY', aws_secret_access_key='YOUR_SECRET_KEY')
conn.get_all_groups()

这样您就可以让 boto 为您处理创建 RegionInfo 对象的复杂问题。

关于python - AutoScaleConnection.get_all_groups() 不适用于 boto,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29237653/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com