You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用AWS CLI部署CloudFormation时传递子网/安全组数组参数报错求助

解决CloudFormation List类型参数传递报错的方法

问题原因

aws cloudformation deploy的--parameter-overrides参数解析JSON文件时,不会自动识别JSON数组为CloudFormation的List类型参数,反而会将数组当作字符串处理,触发类型不匹配的报错。

正确的参数传递方式

方法1:使用JSON文件指定参数(推荐)

修改env.json格式,将List类型的参数值以空格分隔的字符串形式编写,CloudFormation会自动将其解析为List类型。

示例env.json内容:

{
  "EnvSubnets": "subnet-xxxxxx subnet-yyyyyy subnet-zzzzzz",
  "EnvSecGroups": "sg-xxxxxx sg-yyyyyy"
}

执行部署命令:

aws cloudformation deploy --template-file your-template.yaml --stack-name your-stack --parameter-overrides file://env.json

方法2:直接在命令行传递参数

若无需使用JSON文件,可直接在命令行中用空格分隔List参数的值:

aws cloudformation deploy --template-file your-template.yaml --stack-name your-stack --parameter-overrides EnvSubnets="subnet-xxxxxx subnet-yyyyyy" EnvSecGroups="sg-xxxxxx sg-yyyyyy"

验证参数是否正确传递

执行以下命令查看堆栈参数详情,确认List类型参数是否被正确解析:

aws cloudformation describe-stacks --stack-name your-stack --query "Stacks[0].Parameters"

内容的提问来源于stack exchange,提问作者Florian Doyon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 14:25:25