Boto3 script to create instance tag

13,916

See Create Tags. It expects key value arguments. Tags is a list of dictionaries. You can create more than one tag if you want.

ec2.create_tags(Resources=['i-1923943832310'], Tags=[{'Key':'name', 'Value':'apphostname'}])
Share:
13,916
bobby
Author by

bobby

Updated on July 30, 2022

Comments

  • bobby
    bobby over 1 year

    I am trying to create a new tag called Name and value hostname apphostname for an Amazon EC2 instance.

    Below is my code, and it is failing with this error message:

    >>> 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.
    >>>