用于创建实例标记的Boto3脚本

bob*_*bby 3 python amazon-ec2 amazon-web-services python-3.4 boto3

我正在尝试为Amazon EC2实例创建一个名为Name和值hostname 的新标记apphostname.

下面是我的代码,它失败并显示以下错误消息:

>>> ec2.create_tags(["i-1923943832310"], {"name": "apphostname"})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/site-packages/botocore/client.py", line 157, in _api_call
    "%s() only accepts keyword arguments." % py_operation_name)
TypeError: create_tags() only accepts keyword arguments.
>>>
Run Code Online (Sandbox Code Playgroud)

hel*_*loV 7

请参阅创建标签.它期望键值参数.Tags是一个词典列表.如果需要,您可以创建多个标记.

ec2.create_tags(Resources=['i-1923943832310'], Tags=[{'Key':'name', 'Value':'apphostname'}])
Run Code Online (Sandbox Code Playgroud)