Python 3.x 在cygwin上启动amazon ec2实例python boto3

Python 3.x 在cygwin上启动amazon ec2实例python boto3,python-3.x,amazon-ec2,cygwin,boto3,ec2-ami,Python 3.x,Amazon Ec2,Cygwin,Boto3,Ec2 Ami,我正试图通过cygwin上的python3启动一个AmazonEC2实例。 通常在cygwin命令行上,我可以使用以下命令启动实例 aws ec2 start-instances --instance-ids i-03e7f6391a0f523ee 但现在用python3编程并试图通过python脚本启动实例会给我带来错误。这是代码 import sys import boto3 from botocore.exceptions import ClientError instance_id

我正试图通过cygwin上的python3启动一个AmazonEC2实例。 通常在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\u instance.py i-03e7f6391a0f523ee打开
回溯(最近一次呼叫最后一次):
文件“start_instance.py”,第28行,在
ec2.stop_实例(instanceId=[instance_id],DryRun=True)
文件“/usr/lib/python3.6/site packages/botocore/client.py”,第314行,在api调用中
返回self.\u make\u api\u调用(操作名称,kwargs)
文件“/usr/lib/python3.6/site packages/botocore/client.py”,第612行,在make\u api\u调用中
引发错误\u类(解析的\u响应、操作\u名称)
botocore.exceptions.ClientError:调用StopInstances操作时发生错误(InvalidInstanceID.Malformed):无效id:“on”(应为“i-…”)

上面代码中的错误是什么。

我执行脚本的方式有错误。 而不是使用它

python3 start_instance.py i-03e7f6391a0f523ee on
我应该打字的

python3 start_instance.py on i-03e7f6391a0f523ee 
这不会产生错误