【问题标题】:Creating a launch configuration in different region and vpc with Boto使用 Boto 在不同区域和 vpc 中创建启动配置
【发布时间】:2014-06-11 00:55:49
【问题描述】:

我似乎无法在特定区域和定义的 vpc 中创建启动配置。

aws_access_key_id = 'XXX'
aws_secret_access_key = 'XXX'
ec2_keypair = 'XXX'
ec2_security_groups = ['sg-XXXX']
ec2_region = 'us-west-1'
instance_type = 'm1.medium'
user_data = None

# Build the launch configuration
launch_config = LaunchConfiguration(
    name=name, image_id=image_id, key_name=ec2_keypair, user_data=user_data,
    security_groups=ec2_security_groups, instance_type=instance_type)

# Get the Region
conn = EC2Connection(aws_access_key_id=access_key_id,
                     aws_secret_access_key=secret_access_key)
region = next((r for r in conn.get_all_regions() if r.name == ec2_region), None)

# Connect to the Autoscaler
conn = boto.ec2.autoscale.connect_to_region(
           region, aws_access_key_id=access_key_id, 
           aws_secret_access_key=secret_access_key)


conn.create_launch_configuration(launch_config)

当我运行它时,我收到错误No default VPC。这与在命令行 (run_instances) 中执行此操作一致,因此我刚刚添加了子网。

<ErrorResponse xmlns="http://autoscaling.amazonaws.com/doc/2011-01-01/">
  <Error>
    <Type>Sender</Type>
    <Code>ValidationError</Code>
    <Message>No default VPC for this user</Message>
  </Error>

我应该在哪里附加子网或 VPC 才能使其正常工作?

【问题讨论】:

  • 曾经找到答案吗?我目前遇到了同样的错误?

标签: python python-2.7 boto


【解决方案1】:

您需要这样做

    launch_config = LaunchConfiguration(
        name=name, image_id=image_id, key_name=self.ec2_keypair, user_data=user_data,
        security_groups=self.ec2_security_groups, instance_type=str(instance_type),
        associate_public_ip_address=True, )

    conn = boto.ec2.autoscale.connect_to_region(
        self.ec2_region,
        aws_access_key_id=self.access_key_id,
        aws_secret_access_key=self.secret_access_key)

    conn.create_launch_configuration(launch_config)

【讨论】:

    猜你喜欢
    • 2014-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-06
    • 2018-03-29
    • 1970-01-01
    • 2021-08-18
    相关资源
    最近更新 更多