简体   繁体   English

aws ec2 运行实例并指定标签

[英]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.我在让这个脚本使用 --tags 规范选项正确指定标签时遇到了一些困难。

    #!/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
    }
],

I figured it out.我想到了。 I changed ResourceType=String.我更改了 ResourceType=String。 I didn't need the left and right curly braces around each Value in the list.我不需要在列表中的每个 Value 周围使用左花括号和右花括号。 Additionally I needed to add a key value pair for Name to name the ec2 instance in the AWS console.. Name MUST be capitalized.此外,我需要为 Name 添加一个键值对,以便在 AWS 控制台中命名 ec2 实例.. Name 必须大写。

#!/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}]"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM