[英]starting amazon ec2 instance python boto3 on cygwin
我正在嘗試通過cygwin上的python3啟動Amazon ec2實例。 通常在cygwin命令行上,我可以使用以下命令啟動實例
aws ec2 start-instances --instance-ids i-03e7f6391a0f523ee
但是現在在python3中編程並嘗試通過python腳本啟動實例給了我錯誤。 這是代碼
import sys
import boto3
from botocore.exceptions import ClientError
instance_id = sys.argv[2]
action = sys.argv[1].upper()
ec2 = boto3.client('ec2')
if action == 'ON':
# Do a dryrun first to verify permissions
try:
ec2.start_instances(InstanceIds=[instance_id], DryRun=True)
except ClientError as e:
if 'DryRunOperation' not in str(e):
raise
# Dry run succeeded, run start_instances without dryrun
try:
response = ec2.start_instances(InstanceIds=[instance_id], DryRun=False)
print(response)
except ClientError as e:
print(e)
else:
# Do a dryrun first to verify permissions
try:
ec2.stop_instances(InstanceIds=[instance_id], DryRun=True)
except ClientError as e:
if 'DryRunOperation' not in str(e):
raise
# Dry run succeeded, call stop_instances without dryrun
try:
response = ec2.stop_instances(InstanceIds=[instance_id], DryRun=False)
print(response)
except ClientError as e:
print(e)
我在cygwin上運行
python3 start_instance.py i-03e7f6391a0f523ee on
Traceback (most recent call last):
File "start_instance.py", line 28, in <module>
ec2.stop_instances(InstanceIds=[instance_id], DryRun=True)
File "/usr/lib/python3.6/site-packages/botocore/client.py", line 314, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/lib/python3.6/site-packages/botocore/client.py", line 612, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidInstanceID.Malformed) when calling the StopInstances operation: Invalid id: "on" (expecting "i-...")
我上面的代碼有什么錯誤。
我執行腳本的方式出錯。 而不是使用它
python3 start_instance.py i-03e7f6391a0f523ee on
我應該輸入
python3 start_instance.py on i-03e7f6391a0f523ee
這不會出錯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.