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.
>>>
Step 1: Import boto3 and botocore exceptions to handle exceptions. Step 2: secret_location and tags_dict are the required parameters in this function. tags_dict should be as {“key”:”value”,..} Step 3: Create an AWS session using boto3 lib.
In the navigation pane, select a resource type (for example, Instances). Select the resource from the resource list and choose the Tags tab. Choose Manage tags, Add tag. Enter the key and value for the tag.
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'}])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With