如何在aws cloudformation deploy中将参数作为文件传递?(aws cloudformation 创建/更新)

mah*_*hod 1 amazon-web-services aws-cloudformation

我试图使用以下命令更新现有的 cloudformation 堆栈。

aws cloudformation deploy
Run Code Online (Sandbox Code Playgroud)

没有选项传递参数文件部署选项。我们尝试使用 --parameter-overrides 传递参数文件,但出现以下错误。

value passed to --parameter-overrides must be of format Key=Value
Run Code Online (Sandbox Code Playgroud)

我们尝试执行的命令是

aws cloudformation deploy --template-file sg.yml --stack-name Common-SG --parameter-overrides ip.json --no-execute-changeset
Run Code Online (Sandbox Code Playgroud)

有什么方法可以通过aws cloudformation deploy传递文件中的参数

小智 6

在本地文件中传递存储为 JSON 的参数如下所示:

aws cloudformation deploy \
    --stack-name ${CI_PROJECT_NAME}-${STAGE} \
    --template-file deployment.yml \
    --s3-bucket ${CI_BUCKET} \
    --role-arn ${DEPLOYMENT_ROLE} \
    --no-fail-on-empty-changeset \
    --parameter-overrides file://./env/sandbox/config-sandbox.json \

Run Code Online (Sandbox Code Playgroud)

和 config-sandbox.json 这样的。

{
  "Parameters": {
   
    "EnvironmentStage": "sandbox",
   
  }
}

Run Code Online (Sandbox Code Playgroud)

更多详情:https : //aws.amazon.com/fr/blogs/devops/passing-parameters-to-cloudformation-stacks-with-the-aws-cli-and-powershell/

  • 即使使用 aws-cli/2.0.30 传递给 --parameter-overrides 的“['{'] 值必须采用 Key=Value 格式”,这也不起作用 (8认同)

mah*_*hod 3

此问题的解决方法是使用jq命令传递参数。

yum install jq
Run Code Online (Sandbox Code Playgroud)

下面是相同的语法。

aws cloudformation deploy --template-file sg.yml --stack-name Common-SG --parameter-overrides $(jq -r '.[] | [.ParameterKey, .ParameterValue] | "\(.[0])=\(.[1])"' ip.json) --no-execute-changeset
Run Code Online (Sandbox Code Playgroud)