ficestat
ficestat

Reputation: 333

aws ec2 run-instances and specifying tags

I'm having some difficulty getting this script to specify the tags correctly with the --tags specifictions option.

    #!/bin/bash
    ....
    aws ec2 run-instances .... --tag-specifications 
    'ResourceType=string,Tags=[{Key=owner,Value=${ssh_key} 
    {Key=email,Value=${environment} 
    {Key=application,Value=${application}]'

Having trouble figuring out how to get the tags to output right. I have a syntax error somewhere. What am I missing?

"Tags": [
            {
                "Value": "${application",
                "Key": "application"
            },
            {
                "Value": "${environment",
                "Key": "email"
            },
            {
                "Value": "${ssh_key",
                "Key": "owner"
            }
        ],
        "AmiLaunchIndex": 0
    }
],

Upvotes: 1

Views: 2514

Answers (1)

ficestat
ficestat

Reputation: 333

I figured it out. I changed ResourceType=String. I didn't need the left and right curly braces around each Value in the list. Additionally I needed to add a key value pair for Name to name the ec2 instance in the AWS console.. Name MUST be capitalized.

#!/bin/bash
...
aws ec2 run-instances ... --tag-specifications "ResourceType=instance,Tags=
[{Key=owner,Value=$owner},{Key=environment,Value=$environment},
{Key=application,Value=$application}, \
{Key=Name,Value=$name}]"

Upvotes: 1

Related Questions