2014-01-06 24 views
0

我似乎无法在特定区域和已定义的vpc中创建启动配置。在不同地区创建启动配置,并在Boto上创建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

曾经找到一个答案?我目前收到同样的错误? – David

回答

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)