Python 2.7 尝试使用boto创建启动配置时出现AWS错误请求错误。

Python 2.7 尝试使用boto创建启动配置时出现AWS错误请求错误。,python-2.7,amazon-web-services,boto,Python 2.7,Amazon Web Services,Boto,我正在尝试使用boto创建一个启动配置和自动缩放组。我正在根据boto提供的文档构建launch config对象。我甚至确保了launch config对象中每个var的var类型确实是正确的。但是,每次尝试创建启动配置时,我只会收到一个错误的请求 我在谷歌上搜索过,我查过boto代码。我不确定让它从aws返回对此web服务无效的错误是什么 堆栈跟踪 Process loading_nodes: Traceback (most recent call last): File "/Libra

我正在尝试使用boto创建一个启动配置和自动缩放组。我正在根据boto提供的文档构建launch config对象。我甚至确保了launch config对象中每个var的var类型确实是正确的。但是,每次尝试创建启动配置时,我只会收到一个错误的请求

我在谷歌上搜索过,我查过boto代码。我不确定让它从aws返回对此web服务无效的错误是什么

堆栈跟踪

Process loading_nodes:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/grantzukel/Documents/WorkScripts/PythonScripts/elasticsearch-pipeline/loading.cluster.py", line 518, in execute_launch_cluster_provisioning
    provision_object.build_launch_config()
  File "/Users/grantzukel/Documents/WorkScripts/PythonScripts/elasticsearch-pipeline/loading.cluster.py", line 283, in build_launch_config
    self.conn_as.create_launch_configuration(launch_config)
  File "/Library/Python/2.7/site-packages/boto/ec2/autoscale/__init__.py", line 292, in create_launch_configuration
    Request, verb='POST')
  File "/Library/Python/2.7/site-packages/boto/connection.py", line 1208, in get_object
    raise self.ResponseError(response.status, response.reason, body)
BotoServerError: BotoServerError: 400 Bad Request
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>InvalidAction</Code><Message>The action CreateLaunchConfiguration is not valid for this web service.</Message></Error></Errors><RequestID>77fe7035-838b-4842-</RequestID></Response>
启动配置对象的Eclipse变量:

launch_config   LaunchConfiguration: LaunchConfiguration:elasticsearch-data-loader-nodes-cluster    
    associate_public_ip_address bool: True  
    block_device_mappings   <type 'list'>: [{'/dev/sdd': <boto.ec2.blockdevicemapping.BlockDeviceType object at 0x104426190>, '/dev/sde': <boto.ec2.blockdevicemapping.BlockDeviceType object at 0x104426310>, '/dev/sdb': <boto.ec2.blockdevicemapping.BlockDeviceType object at 0x1044262d0>, '/dev/sdc': <boto.ec2.blockdevicemapping.BlockDeviceType object at 0x104426390>}]   
        __len__ int: 1  
        0   BlockDeviceMapping: {'/dev/sdd': <boto.ec2.blockdevicemapping.BlockDeviceType object at 0x104426190>, '/dev/sde': <boto.ec2.blockdevicemapping.BlockDeviceType object at 0x104426310>, '/dev/sdb': <boto.ec2.blockdevicemapping.BlockDeviceType object at 0x1044262d0>, '/dev/sdc': <boto.ec2.blockdevicemapping.BlockDeviceType object at 0x104426390>}    
            __len__ int: 4  
            '/dev/sdb' (4366447312) BlockDeviceType: <boto.ec2.blockdevicemapping.BlockDeviceType object at 0x1044262d0>    
                attach_time NoneType: None  
                connection  NoneType: None  
                delete_on_termination   bool: True  
                encrypted   NoneType: None  
                ephemeral_name  NoneType: None  
                iops    int: 100    
                no_device   bool: False 
                size    int: 10 
                snapshot_id NoneType: None  
                status  NoneType: None  
                volume_id   NoneType: None  
                volume_type str: io1    
            '/dev/sdc' (4366447360) BlockDeviceType: <boto.ec2.blockdevicemapping.BlockDeviceType object at 0x104426390>    
                attach_time NoneType: None  
                connection  NoneType: None  
                delete_on_termination   bool: True  
                encrypted   NoneType: None  
                ephemeral_name  NoneType: None  
                iops    int: 100    
                no_device   bool: False 
                size    int: 10 
                snapshot_id NoneType: None  
                status  NoneType: None  
                volume_id   NoneType: None  
                volume_type str: io1    
            '/dev/sdd' (4366447408) BlockDeviceType: <boto.ec2.blockdevicemapping.BlockDeviceType object at 0x104426190>    
                attach_time NoneType: None  
                connection  NoneType: None  
                delete_on_termination   bool: True  
                encrypted   NoneType: None  
                ephemeral_name  NoneType: None  
                iops    int: 100    
                no_device   bool: False 
                size    int: 10 
                snapshot_id NoneType: None  
                status  NoneType: None  
                volume_id   NoneType: None  
                volume_type str: io1    
            '/dev/sde' (4366447456) BlockDeviceType: <boto.ec2.blockdevicemapping.BlockDeviceType object at 0x104426310>    
                attach_time NoneType: None  
                connection  NoneType: None  
                delete_on_termination   bool: True  
                encrypted   NoneType: None  
                ephemeral_name  NoneType: None  
                iops    int: 100    
                no_device   bool: False 
                size    int: 10 
                snapshot_id NoneType: None  
                status  NoneType: None  
                volume_id   NoneType: None  
                volume_type str: io1    
    classic_link_vpc_id NoneType: None  
    classic_link_vpc_security_groups    ListElement: [] 
    connection  NoneType: None  
    created_time    NoneType: None  
    delete_on_termination   bool: True  
    ebs_optimized   bool: True  
    image_id    str: ami-38213659   
    instance_monitoring bool: True  
    instance_profile_name   str: arn:aws:iam::00000000000:instance-profile/elasticsearchRole    
    instance_type   str: c4.large   
    iops    NoneType: None  
    kernel_id   NoneType: None  
    key_name    str: main-access    
    launch_configuration_arn    NoneType: None  
    name    str: elasticsearch-data-loader-nodes-cluster    
    ramdisk_id  NoneType: None  
    security_groups ListElement: ['sg-1d7d0000']    
    spot_price  NoneType: None  
    use_block_device_types  bool: True  
    user_data   str: export verson=1.0 \n export a_or_b=a \n export environment=dev 
    volume_type NoneType: None  

我完全理解这样做的痛苦,我以前也有过这样的经历。但是现在我们移动到新工具
terraform
,您可以试一试。但是如果你真的喜欢编程,继续使用boto.lol我找到了答案,稍后我会发布它,我也在做terraform我有一个脚本,可以用参数构建terraform文件,但是这个脚本是用于通过消息传递等控制数据传递的。因此,使用一种技术更容易。
def __init__(self, properties_dict = None):

    '''
        these are strings
    '''
    self.region = str(properties_dict['region']).encode("utf-8")
    self.lc_name = str(properties_dict['lc_name']).encode("utf-8")
    self.ami = str(properties_dict['ami']).encode("utf-8")
    self.ssh_key = str(properties_dict['ssh_key']).encode("utf-8")
    self.instance_type = str(properties_dict['instance_type']).encode("utf-8")
    self.instance_profile_name = str(properties_dict['instance_profile_name']).encode("utf-8")
    self.asg_name = str(properties_dict['asg_name']).encode("utf-8")
    self.health_check_period = str(properties_dict['health_check_period']).encode("utf-8")
    self.health_check_type = str(properties_dict['health_check_type']).encode("utf-8")
    self.user_data = str(properties_dict['user_data']).encode("utf-8")

    self.min_size = str(properties_dict['min_size']).encode("utf-8")
    self.max_size = str(properties_dict['max_size']).encode("utf-8")
    self.desired_capacity = str(properties_dict['desired_capacity']).encode("utf-8")

    self.availability_zones = str(properties_dict['availability_zones']).encode("utf-8")
    self.vpc_zone_identifier = str(properties_dict['vpc_zone_identifier']).encode("utf-8")
    self.tags = properties_dict['tags']
    self.security_groups = properties_dict['security_groups']
    self.block_device_mappings = properties_dict['block_device_mappings']

    self.launch_config_obj = None

    self.ebs_optimized = True
    self.associate_public_ip_address = True
    self.instance_monitoring = True

    self.aws_access_key_id = str(properties_dict['aws_access_key']).encode("utf-8")
    self.aws_secret_access_key = str(properties_dict['aws_secret_key']).encode("utf-8")
    #connection object
    self.conn_as = AutoScaleConnection(region=boto.ec2.get_region(self.region), 
                                       aws_access_key_id=self.aws_access_key_id,
                                       aws_secret_access_key=self.aws_secret_access_key,
                                       use_block_device_types=True)

def create_auto_scale_group(self):

    tags = []
    for tag in self.tags:
        tags.append(boto.ec2.autoscale.tag.Tag(key = tag.split(':')[0], value = tag.split(':')[1], propagate_at_launch = True, resource_id=self.asg_name))

    avail_zones = []
    for zone in self.availability_zones.split(","):
        avail_zones.append(zone)   


    print tags, avail_zones, self.launch_config_obj    

    auto_scale_group = AutoScalingGroup(
                          name = self.asg_name,
                          availability_zones=avail_zones,
                          desired_capacity=self.desired_capacity,
                          launch_config=self.launch_config_obj,
                          health_check_period=self.health_check_period,
                          health_check_type=self.health_check_type,
                          max_size=self.max_size,
                          min_size=self.min_size,
                          vpc_zone_identifier=self.vpc_zone_identifier,
                          tags=tags
                          )
    #create asg
    self.conn_as.create_auto_scaling_group(auto_scale_group)
    return self

def build_launch_config(self):

    groups = [];
    for group in self.security_groups:
        groups.append(str(group).encode("utf-8"))

    block_device_mappings_built = BlockDeviceMapping()

    for device in self.block_device_mappings:

        device_ebs = None

        name = str(device.split(",")[0]).encode("utf-8")
        size = str(device.split(",")[1]).encode("utf-8")
        type = str(device.split(",")[2]).encode("utf-8")
        iops = str(device.split(",")[3]).encode("utf-8")

        device_ebs = EBSBlockDeviceType()
        device_ebs.size = int(size)
        device_ebs.delete_on_termination = True
        device_ebs.iops = int(iops)
        device_ebs.volume_type=type

        block_device_mappings_built[name] = device_ebs 

        self.launch_config_obj = LaunchConfiguration(name=self.lc_name,
                                                 image_id=self.ami,
                                                 key_name=self.ssh_key,
                                                 security_groups=groups,
                                                 user_data=self.user_data,
                                                 instance_type=self.instance_type,
                                                 use_block_device_types=True,
                                                 block_device_mappings=[block_device_mappings_built],
                                                 instance_monitoring=True,
                                                 instance_profile_name=self.instance_profile_name,
                                                 ebs_optimized=True,
                                                 associate_public_ip_address=True)

    self.conn_as.create_launch_configuration(self.launch_config_obj)
    return self
    #self.conn_as.create_launch_configuration(lc)