2017-11-06 35 views
-1

boto3を使用してEC2 instanceを開始しようとしています。私は以下のコードを実行すると、それは細かいAWS EC2のstart_instances()はキーワード引数のみを受け入れます。

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 (most recent call last): File "/Users/xxx/PycharmProjects/ctm-scripting-utils/ec2/start_instances.py", line 25, in StartInstances().start_ec_instances("InstanceIds=[\'i-XXXXXXXXXX\']") File "/Users/xxx/PycharmProjects/ctm-scripting-utils/ec2/start_instances.py", line 11, in start_ec_instances response = ec2client.start_instances(instanceids) File "/Users/xxx/Library/Python/3.6/lib/python/site-packages/botocore/client.py", line 310, in _api_call "%s() only accepts keyword arguments." % py_operation_name) TypeError: start_instances() only accepts keyword arguments.

答えて

2

Pythonの質問の多くを得ます。 kwargsInstanceIds=[..]の代わりにstring'InstanceIds=[\'i-XXXXXXXXXX\']'を渡そうとしています。解決できる方法の1つは、

class StartInstances: 
    def start_ec_instances(self, instanceid): 
     response = ec2client.start_instances(InstanceIds=[instanceid]) 
     return 

StartInstances().start_ec_instances('i-XXXXXXXXXX') 
です。
関連する問題