【问题标题】:Python Boto: How do you specify a subnet id AND a security group?Python Boto:如何指定子网 ID 和安全组?
【发布时间】:2014-05-27 01:36:32
【问题描述】:

我正在尝试使用 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>

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

【问题讨论】:

    标签: python amazon-web-services amazon-ec2 boto


    【解决方案1】:

    因为您要在 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-27
      • 1970-01-01
      • 2014-09-08
      • 2017-03-12
      • 1970-01-01
      • 2015-06-07
      相关资源
      最近更新 更多