2014-01-06 50 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)