2016-01-15 104 views
0

有誰知道如何設置虛擬化類型當啓動aws ec2實例使用boto3?我試着指定虛擬化類型時啓動aws ec2實例與boto3

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,因爲我需要一些舊的實例類型(的m1.small)只允許半虛擬代替hvm,看來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_instanceshttp://boto3.readthedocs.org/en/latest/reference/services/ec2.html#EC2.Client.run_instances

而且也沒有VirtualizationType在PARAMS,所以我不知道是否有方法來設置或因爲它要被棄用所以boto3只是不允許指定此?

歡迎任何提示或建議,並提前致謝!

+0

您需要實例類型爲m1.small的原因是什麼? –

+0

爲了向後兼容,我們有一些使用m1.small的現有腳本,我們正在做基準測試,因此需要完全相同的規格。 –

回答

3

無法從HVM AMI映像啓動半虛擬EC2實例。這不僅僅是一個boto3的事情,這是一個AWS限制。半虛擬EC2實例只能從半虛擬AMI啓動。

這是因爲PV EC2實例啓動方式與HVM EC2實例相比存在差異。

爲了啓動Linux m1.small實例,您需要查找和/或創建一個Paravirtual AMI映像。

+0

啊,謝謝!我誤導了錯誤信息,所以AMI ID與VirtualizationType相關聯,我找到了AMI ID,非常感謝! –