2016-03-01 71 views
10

我试图用boto3创建一个实例实例。虽然我遵循API documentation,但我收到了一个我无法弄清楚的例外情况。我正在使用的代码是:boto3:竞价实例创建

import boto3 
import datetime 
client = boto3.client('ec2') 
response = client.request_spot_instances(
    DryRun=False, 
    SpotPrice='0.10', 
    ClientToken='string', 
    InstanceCount=1, 
    Type='one-time', 
    LaunchSpecification={ 
     'ImageId': 'ami-fce3c696', 
     'KeyName': 'awskey.pem', 
     'SecurityGroups': ['sg-709f8709'], 
     'InstanceType': 'm4.large', 
     'Placement': { 
      'AvailabilityZone': 'us-east-1a', 
     }, 
     'BlockDeviceMappings': [ 
      { 
       'Ebs': { 
        'SnapshotId': 'snap-f70deff0', 
        'VolumeSize': 100, 
        'DeleteOnTermination': True, 
        'VolumeType': 'gp2', 
        'Iops': 300, 
        'Encrypted': False 
       }, 
      }, 
     ], 

     'EbsOptimized': True, 
     'Monitoring': { 
      'Enabled': True 
     }, 
     'SecurityGroupIds': [ 
      'sg-709f8709', 
     ] 
    } 
) 

我收到以下异常:

botocore.exceptions.ClientError: An error occurred (InvalidParameterValue) when calling the RequestSpotInstances operation: Value() for parameter groupId is invalid. The value cannot be empty 

的事情是有在API documentation请求没有的groupId参数。

我错过了什么吗?

回答

16

虽然没有在API文档中指定,但显然'SecurityGroups'参数需要安全组的名称,而不是ID。

更改为组名解决了问题。

感谢任何人打扰读一下这个问题。

+5

这只是节省了我的时间。 – Brett