2016-03-01 16 views
10

Ich versuche, eine Spot-Instanz mit Boto3 zu erstellen. Obwohl ich der API documentation folge, erhalte ich eine Ausnahme, die ich nicht herausfinden konnte. Der Code Ich verwende ist:boto3: Spot-Instanz-Erstellung

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', 
     ] 
    } 
) 

Und ich erhalte die folgende Ausnahme:

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

Die Sache ist es in der Anfrage keine groupId Parameter im API documentation ist.

Fehle ich etwas?

Antwort

16

Obwohl es in der API-Dokumentation nicht angegeben ist, erfordert der Parameter 'SecurityGroups' offenbar die Namen der Sicherheitsgruppen, nicht die IDs.

Das Ändern des Gruppennamens löste das Problem.

Vielen Dank für jeden, der die Frage zuerst gelesen hat.

+5

Das hat mir nur Stunden gespart. – Brett