我似乎无法在特定区域和已定义的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才能使用?
答案 0 :(得分:0)
以下是您需要执行此操作的方法
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)