6

Executing query:

aws ec2 run-instances --image-id ami-7a85a01a --security-group-ids sg-756ae512 --count 1 --instance-type t2.micro --tag-specifications ResourceType=instance,Tags=[{Key=webserver,Value=production}] --subnet-id subnet-cc0b0e8a

Its throwing an error saying:

Unknown options: --tag-specifications, ResourceType=instance,Tags=[{Key=webserver,Value=production}]

Does anybody know if this is depricated, or is the syntax different from expected? I've been running in circles with this.

Possible solution with new syntax:

aws ec2 run-instances --image-id ami-xxxxxxxxxx  --security-group-ids sg-ef95c791 --count 1 --instance-type m4.2xlarge --key-name mypemkey --query Reservations[*].Instances[*].[PublicIpAddress,InstanceId]

The best I can come up with, seems to be working:

aws ec2 run-instances --image-id ami-7a85a01a --count 1 --instance-type t2.micro --key-name mykeypair --subnet-id sn-756ae512 --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=production}]' --associate-public-ip-address --output=text

Mattehicks
  • 151
  • 1
  • 2
  • 16
  • Your edit only shows that you removed the `--tag-specification` option, WTF? – Douglas Held Jul 29 '17 at 14:51
  • Correct answer is below. Needed to upgrade.Mostly the docs told me I cant add tags during instance creation. I posted the last command I got working, which will return the instance-id, which could be passed to the next command - to tag the instance. – Mattehicks Nov 05 '17 at 23:33

4 Answers4

8

I ran into this issue today and figured it out after an hour or so of struggling through the infamously horrendous AWS documentation.

The problem was that the installation instructions (pip install and using the bundled installer) are just wrong: though the commands were copied perfectly and the requirements (specifically the "Python 2 version 2.6.5+ or Python 3 version 3.3+") were met, the aws-cli package would never install/update past 1.11.13.

The solution: use pip3 install instead of pip install. This updated it to 1.11.97, which enabled the --tag-specifications parameter. I don't know if this will solve the problem for you, but I suspect many Ubuntu users will experience this, so I decided to post it anyway.

  • My system is running pip 9.0.1 and Python 2.7, and I did not have this problem. So, I have offered my own answer. – Douglas Held Jul 29 '17 at 14:48
  • The lack of consistency in aws products is baffling, so having many different possible solutions is always welcome. Bezos works in mysterious ways. – Jonathan Voss Jul 31 '17 at 19:45
  • I don't think it's baffling. The whole idea is that independent teams wrote their own entry points. It's natural that a coding style didn't coalesce until much of the work was done. – Douglas Held Aug 15 '17 at 18:49
2

Your syntax is correct, per the documentation; but your AWS client is too old to support the --tag-specifications option.

[On OS X, at least] use pip install --upgrade --user awscli to upgrade the client to the current version.

Douglas Held
  • 1,452
  • 11
  • 25
0

found an answer. Different syntax in the call: http://docs.aws.amazon.com/cli/latest/reference/ec2/run-instances.html

edit:

QUERY=$(aws ec2 run-instances --image-id ${AMI_ID} --count 1 --instance-type t2.micro --key-name ${KEY_PAIR} --subnet-id ${SUBNET_ID} \
 --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value='${EC2_TAG}'}]' --associate-public-ip-address --output=text )
Mattehicks
  • 151
  • 1
  • 2
  • 16
  • 2
    Can you include your completed, correct code sample for future readers? Simply linking to the documentation with no comment as to what change you actually made isn't a sufficient answer on Stack Overflow. – Anthony Neace May 17 '17 at 23:47
  • Shared my workaround, not using the 'name' tag. I'm using CONemu emulator - so pip is not installed. I think Jonathan Voss' solution was probably the right answer. AWS CLI syntax can be tricky. – Mattehicks Jun 26 '17 at 21:15
-1

You are missing a single quote for ' --tag-specifications value:

eg. from aws ec2 run-instances documentation:

aws ec2 run-instances --image-id ami-abc12345 --count 1 --instance-type t2.micro --key-name MyKeyPair --subnet-id subnet-6e7f829e --tag-specifications 'ResourceType=instance,Tags=[{Key=webserver,Value=production}]' 'ResourceType=volume,Tags=[{Key=cost-center,Value=cc123}]'
Yeshodhan Kulkarni
  • 2,844
  • 1
  • 16
  • 19