2016-03-01 54 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