【发布时间】:2017-11-06 23:52:38
【问题描述】:
我正在尝试使用boto3 启动EC2 instance。当我执行以下代码时,它工作正常
import boto3
ec2client = boto3.client('ec2')
class StartInstances:
def start_ec_instances(self):
response = ec2client.start_instances(InstanceIds=['i-XXXXXXXXXX'])
return
StartInstances().start_ec_instances()
但是当我运行下面的代码时,我得到了
import boto3
ec2client = boto3.client('ec2')
class StartInstances:
def start_ec_instances(self, instanceid):
response = ec2client.start_instances(instanceid)
return
StartInstances().start_ec_instances('InstanceIds=[\'i-XXXXXXXXXX\']')
Traceback(最近一次调用最后一次):文件 "/Users/xxx/PycharmProjects/ctm-scripting-utils/ec2/start_instances.py", 第 25 行,在 StartInstances().start_ec_instances("InstanceIds=[\'i-XXXXXXXXXX\']") 文件 "/Users/xxx/PycharmProjects/ctm-scripting-utils/ec2/start_instances.py", 第 11 行,在 start_ec_instances 响应 = ec2client.start_instances(instanceids) 文件“/Users/xxx/Library/Python/3.6/lib/python/site-packages/botocore/client.py”, 第 310 行,在 _api_call 中 “%s() 只接受关键字参数。” % py_operation_name) TypeError: start_instances() 只接受关键字参数。
【问题讨论】:
标签: python amazon-web-services amazon-ec2 boto3