Shailesh Sutar
Shailesh Sutar

Reputation: 399

aws cli returning unknown options on create-image command

I am running below command to create ami from existing ec2 server with tags. Below is the command I am using to run on redhat linux 8.3

aws ec2 create-image --instance-id $instance_id --name "$ami_name" --region $region --description "$desc" --no-reboot --tags-specifications 'ResourceType=image,Tags=[{Key='Owner',Value='Some_one'},{Key='Environment',Value='Production:Dev'},{Key='Stack',Value='ETL'},{Key='Role',Value='Database'}]'

I am substituting all the variables correctly however the --tags-specifications is having some issue. I tried below options with tags-specifications but none of them are working for me.

--tags-specifications 'ResourceType=image,Tags=[{Key=Owner,Value="Some_one"},{Key=Environment,Value="Production:Dev"},{Key=Stack,Value="ETL"},{Key=Role,Value="Database"}]'
--tags-specifications 'ResourceType=image,Tags=[{Key=Owner,Value=Some_one},{Key=Environment,Value=Production:Dev},{Key=Stack,Value=ETL},{Key=Role,Value=Database}]'
--tags-specifications 'ResourceType=image,Tags=[{Key='Owner',Value="Some_one"},{Key='Environment',Value="Production:Dev"},{Key='Stack',Value="ETL"},{Key='Role',Value="Database"}]'
--tags-specifications, ResourceType=image,Tags=[{Key="Owner",Value="Some_one"},{Key="Environment",Value="Non-Production:Dev"},{Key="Stack",Value="ETL"},{Key="Role",Value="Database"}]

Can someone tell me what is wrong here?

Upvotes: 1

Views: 2394

Answers (2)

Adil Hindistan
Adil Hindistan

Reputation: 6615

You did not specify what the error was or the aws cli version you are using. As you corrected the typo you had with --tag-specification, I am guessing problem may be the version of the aws-cli you are using.

AWS did not have an option to add tags during image creation until December 2020. If you happen to have an aws-cli version that is a few months old, when you run the command to create the image and add the tags, you might get an error similar to:

unknown options: --tag-specifications, ResourceType=image,Tags=[{Key=somekey,Value=some value}]

If that's the case, try upgrading your aws cli. Not sure how you installed it but if you used pip, something like the following should upgrade it, assuming you do have access to later versions:

python3 -m pip install awscli --upgrade

Upvotes: 1

Marcin
Marcin

Reputation: 238877

It should be --tag-specifications:

aws ec2 create-image --instance-id $instance_id --name "$ami_name" --region $region --description "$desc" --no-reboot --tag-specifications 'ResourceType=image,Tags=[{Key='Owner',Value='Some_one'},{Key='Environment',Value='Production:Dev'},{Key='Stack',Value='ETL'},{Key='Role',Value='Database'}]'

Upvotes: 1

Related Questions