我在使用--tags specifictions选项正确指定标记时遇到了一些困难。
#!/bin/bash
type=${1}
image_ami=${2}
subnets=${3}
sec_groups=${4}
ssh_key=${5}
environment=${6}
application=${7}
aws ec2 run-instances --instance-type ${type} --image-id
${image_ami} --subnet-id ${subnets} --security-group-i
${sec_groups} --associate-public-ip-address --tag-specifications
'ResourceType=string,Tags=[{Key=owner,Value=${ssh_key}
{Key=email,Value=${environment}
{Key=application,Value=${application}]'
无法弄清楚如何让标签输出正确。我某处有语法错误。我错过了什么?
"Tags": [
{
"Value": "${application",
"Key": "application"
},
{
"Value": "${environment",
"Key": "email"
},
{
"Value": "${ssh_key",
"Key": "owner"
}
],
"AmiLaunchIndex": 0
}
],
答案 0 :(得分:0)
我明白了。我更改了ResourceType = String。我并不需要在列表中的每个值周围使用左右花括号。另外,我需要为Name添加一个键值对,以便在AWS控制台中命名ec2实例。名称必须大写。
#!/bin/bash
#test "$#" -ge 4 || { echo "Expected at least 7 args; received $#" >&2
; exit 1; }
#set -xe
#groovy default parameters for Jenkinsfile
type=${1}
image_ami=${2}
subnet_id=${3}
sec_groups=${4}
ssh_key_name=${5}
owner=${6}
environment=${7}
application=${8}
name=${9}
aws ec2 run-instances --instance-type ${type} --image-id ${image_ami} -
-key-name ${ssh_key_name} --subnet-id ${subnet_id} --security-group-ids
${sec_groups} --associate-public-ip-address \
--tag-specifications "ResourceType=instance,Tags=
[{Key=owner,Value=$owner},{Key=environment,Value=$environment},
{Key=application,Value=$application}, \
{Key=Name,Value=$name}]"