gpt4 book ai didi

python 博托 : How do you specify a subnet id AND a security group?

转载 作者:太空狗 更新时间:2023-10-29 20:54:08 26 4
gpt4 key购买 nike

我正在尝试使用 boto 启动一个实例。该实例需要在我的 VPC 内的特定子网上以及我的 VPC 内的特定安全组中启动。

以下代码在正确子网上的我的 VPC 中成功启动了一个实例:

conn.run_instances(
image_id=base_ami,
key_name=bakery_key,
subnet_id=bakery_subnet)

下面的代码给我以下错误:

reservation = conn.run_instances(
image_id=base_ami,
key_name=bakery_key,
security_groups=['TheNameOfMySecurityGroup'],
subnet_id=bakery_subnet)

这是我得到的错误。当我指定使用子网 ID 而不是子网的实际名称时,我得到了同样的错误:

Traceback (most recent call last):
File "./botobakery.py", line 24, in <module>
subnet_id=bakery_subnet)
File "/usr/lib/python2.6/site-packages/boto/ec2/connection.py", line 935, in run_instances
verb='POST')
File "/usr/lib/python2.6/site-packages/boto/connection.py", line 1177, in get_object
raise self.ResponseError(response.status, response.reason, body)
boto.exception.EC2ResponseError: EC2ResponseError: 400 Bad Request
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>InvalidParameterCombination</Code><Message>The parameter groupName cannot be used with the parameter subnet</Message></Error></Errors> <RequestID>c8a6b824-4ab3-41d2-9633-9830c167d2d6</RequestID></Response>

如果有人知道如何将我的实例启动到我的特定子网和我的特定安全组中,我将非常感激和感激

最佳答案

因为您是在 VPC 中启动,所以您必须通过 ID 而不是名称来指定安全组。名称仅在“经典”EC2 中有效。因此,如果相关安全组的 ID 为 sg-12345678,您可以使用如下命令:

reservation = conn.run_instances(
image_id=base_ami,
key_name=bakery_key,
security_group_ids=['sg-12345678'],
subnet_id=bakery_subnet)

关于 python 博托 : How do you specify a subnet id AND a security group?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23037291/

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