【发布时间】:2016-01-15 12:17:47
【问题描述】:
有人知道在使用 boto3 启动 aws ec2 实例时如何设置 VirtualizationType 吗?我试过了
session = boto3.session.Session(
aws_access_key_id=self.access_key_id,
aws_secret_access_key=self.secret_access_key,
region_name=self.region)
ec2resource = session.resource('ec2')
ec2resource.create_instances(
ImageId=ami_id, MinCount=1, MaxCount=count, KeyName=key_name,
InstanceType=type, SecurityGroups=security_groups,
VirtualizationType='paravirtual')
但是得到了
[2016-01-15 10:54:18 CST] INFO Calling ec2:run_instances with {'VirtualizationType': 'paravirtual', 'KeyName': 'common', 'SecurityGroups': ['default'], 'MaxCount': 2, 'MinCount': 1, 'InstanceType': 'm1.small', 'ImageId': 'ami-d05e75b8'}
Traceback (most recent call last):
File "suites/ec2.py", line 21, in <module>
print ec2.launch(count=2, VirtualizationType='paravirtual')
File "/Users/bchung/Dropbox/PycharmProjects/perf/lib/aws/ec2.py", line 183, in launch
InstanceType=type, SecurityGroups=security_groups, **kwargs)
File "/Library/Python/2.7/site-packages/boto3/resources/factory.py", line 455, in do_action
response = action(self, *args, **kwargs)
File "/Library/Python/2.7/site-packages/boto3/resources/action.py", line 79, in __call__
response = getattr(parent.meta.client, operation_name)(**params)
File "/Library/Python/2.7/site-packages/botocore/client.py", line 310, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Library/Python/2.7/site-packages/botocore/client.py", line 383, in _make_api_call
api_params, operation_model, context=request_context)
File "/Library/Python/2.7/site-packages/botocore/client.py", line 425, in _convert_to_request_dict
api_params, operation_model)
File "/Library/Python/2.7/site-packages/botocore/validate.py", line 273, in serialize_to_request
raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError:
Parameter validation failed:
Unknown parameter in input: "VirtualizationType", must be one of:
DryRun, ImageId, MinCount, MaxCount, KeyName, SecurityGroups,
SecurityGroupIds, UserData, InstanceType, Placement, KernelId,
RamdiskId, BlockDeviceMappings, Monitoring, SubnetId,
DisableApiTermination, InstanceInitiatedShutdownBehavior,
PrivateIpAddress, ClientToken, AdditionalInfo, NetworkInterfaces,
IamInstanceProfile, EbsOptimized
我需要设置 VirtualizationType 因为我需要一些只允许 paravirtual 而不是 hvm 的旧实例类型 (m1.small) ,并且似乎 boto3 默认使用 hvm :
Traceback (most recent call last):
File "suites/ec2.py", line 21, in <module>
print ec2.launch(count=2)
File "/Users/bchung/Dropbox/PycharmProjects/perf/lib/aws/ec2.py", line 183, in launch
InstanceType=type, SecurityGroups=security_groups, **kwargs)
File "/Library/Python/2.7/site-packages/boto3/resources/factory.py", line 455, in do_action
response = action(self, *args, **kwargs)
File "/Library/Python/2.7/site-packages/boto3/resources/action.py", line 79, in __call__
response = getattr(parent.meta.client, operation_name)(**params)
File "/Library/Python/2.7/site-packages/botocore/client.py", line 310, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Library/Python/2.7/site-packages/botocore/client.py", line 396, in _make_api_call
raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred
(InvalidParameterCombination) when calling the RunInstances operation:
Non-Windows instances with a virtualization type of 'hvm' are currently not supported for this instance type.
我检查了: http://boto3.readthedocs.org/en/latest/reference/services/ec2.html#EC2.ServiceResource.create_instances 和 http://boto3.readthedocs.org/en/latest/reference/services/ec2.html#EC2.Client.run_instances
并且参数中没有 VirtualizationType,所以我想知道是否有办法设置或者因为它将被弃用,所以 boto3 只是不允许指定这个?
欢迎任何提示或建议,提前致谢!
【问题讨论】:
-
您要求实例类型为 m1.small 的原因是什么?
-
为了向后兼容,我们有一些使用 m1.small 的现有脚本,并且我们正在进行基准测试,因此需要完全相同的规范。
标签: python amazon-web-services amazon-ec2 boto3