问题描述
我正在使用 this CloudFormation template
我试图传递值的 List 参数是:
"subnets" : {
"Type" : "List<AWS::EC2::subnet::Id>","Description" : "The list of subnetIds in your Virtual Private Cloud (VPC)","ConstraintDescription" : "must be a list of at least two existing subnets associated with at least two different availability zones. They should be residing in the selected Virtual Private Cloud."
},
我写了一个看起来像这样的实用程序脚本:
#!/bin/bash
subnet1=subnet-abcdef
subnet2=subnet-ghijlm
echo -e "\n==deploying stack.cf.yaml===\n"
aws cloudformation deploy \
--region $REGION \
--profile $CLI_PROFILE \
--stack-name $STACK_NAME \
--template-file stack.cf.json \
--no-fail-on-empty-changeset \
--capabilities CAPABILITY_NAMED_IAM \
--parameter-overrides \
VpcId=$VPC_ID \
subnets="$subnet1 $subnet2" \ #<---------------this fails
InstanceType=$EC2_INSTANCE_TYPE \
OperatorEMail=$OPERATOR_EMAIL \
KeyName=$KEY_NAME \
如果我部署它,一段时间后我的堆栈无法部署,说值为“subnet-abcdef subnet-ghijlmn”的子网不存在。
解决方法
将参数传递给列表的正确方法是用逗号分隔它们
所以:
#!/bin/bash
SUBNET1=subnet-abcdef
SUBNET2=subnet-ghijlm
aws cloudformation deploy --parameter-overrides Subnets="$SUBNET1,SUBNET2"
会起作用