【发布时间】:2016-06-13 18:59:09
【问题描述】:
我正在尝试使用 boto3 创建一个现场实例。虽然我关注API documentation,但我收到了一个我无法弄清楚的异常。我使用的代码是:
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参数。
我错过了什么吗?
【问题讨论】:
-
为什么要同时指定
SecurityGroups和SecurityGroupIds?看起来您只需要SecurityGroupIds,因为您传递的是 sg id 而不是名称。
标签: python amazon-web-services amazon-ec2 boto boto3