Cloudformation deploy --parameter-overrides 不接受文件解决方法
Cloudformation deploy --parameter-overrides doesnt accept file Workaround
我正在使用 codebuild 设置管道,并使用 cloudformation 包和 cloudformation deploy 来启动运行 lambda 函数的堆栈。现在我知道,通过 cloudformation 部署,我们不能将参数文件与 --parameters-overrides 一起使用,并且此功能请求仍处于开放状态,AWS https://github.com/aws/aws-cli/issues/2828 . So i am trying to use a workaround using JQ which is decsribed in this link https://github.com/aws/aws-cli/issues/3274#issuecomment-529155262 如下所示。
PARAMETERS_FILE="parameters.json" && PARAMS=($(jq -r '.Parameters[] | [.ParameterKey, .ParameterValue] | "\(.[0])=\(.[1])"' ${PARAMETERS_FILE})) - aws cloudformation deploy --template-file /codebuild/output/packaged.yaml --region us-east-2 --stack-name InitialSetup --capabilities CAPABILITY_IAM --parameter-overrides ${PARAMS[@]}
如果通过 cli 进行测试,此解决方法效果很好。我还在容器内尝试了此解决方法,因为 buildspec.yaml 文件在后台创建了一个容器,其中 运行 执行这些命令,但代码构建不执行 aws cloudformation 部署步骤并失败。我收到错误 "aws: error: argument --parameter-overrides: expected at least one argument" 。我什至尝试在 shell 脚本中复制解决方法的两个步骤,然后执行它,但我 运行 进入错误“[Container] 2020/01/21 09:19:14 阶段上下文状态代码:COMMAND_EXECUTION_ERROR 消息:执行命令时出错:./test.sh。原因:退出状态 255"
有人可以在这里指导我吗?我的 buildspec.yaml 文件如下:
'''
版本:0.2
阶段:
安装:
运行时间版本:
java: corretto8
命令:
- wget -O jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
- chmod +x ./jq
- cp jq /usr/bin
- jq --version
pre_build:
命令:
# - echo "[预构建阶段]
构建:
命令:
- aws cloudformation package --template-file master.yaml --s3-bucket rtestbucket --output-template-file packaged.yaml
- aws s3 cp ./packaged.yaml s3://rtestbucket/packaged.yaml
- aws s3 cp s3://rtestbucket/packaged.yaml /codebuild/output
post_build:
命令:
- PARAMETERS_FILE="parameters.json" && PARAMS=($(jq -r '.Parameters[] | [.ParameterKey, .ParameterValue] | "\(.[0])=\(.[1])"' ${PARAMETERS_FILE}))
- ls
- aws cloudformation deploy --template-file /codebuild/output/packaged.yaml --region us-east-2 --stack-name InitialSetup --capabilities CAPABILITY_IAM --parameter-overrides ${PARAMS[@]}
工件:
类型:邮编
文件:
- packaged.yaml
表达式 ${PARAMS[@]}
没有返回任何值,这导致错误 aws: error: argument --parameter-overrides: expected at least one argument
。查看代码并解决或删除该参数。
CodeBuild buildspec 命令在 bash shell 中不是 运行 我认为语法:
${PARAMS[@]}
... 是 bash 具体的。
根据这里的回答:
Try to wrap your commands in a script file with a shebang specifying the shell you'd like the commands to execute with.
我能够通过执行 shell 脚本中的所有必需步骤并提供对脚本的访问来解决此问题。
我正在使用 codebuild 设置管道,并使用 cloudformation 包和 cloudformation deploy 来启动运行 lambda 函数的堆栈。现在我知道,通过 cloudformation 部署,我们不能将参数文件与 --parameters-overrides 一起使用,并且此功能请求仍处于开放状态,AWS https://github.com/aws/aws-cli/issues/2828 . So i am trying to use a workaround using JQ which is decsribed in this link https://github.com/aws/aws-cli/issues/3274#issuecomment-529155262 如下所示。
PARAMETERS_FILE="parameters.json" && PARAMS=($(jq -r '.Parameters[] | [.ParameterKey, .ParameterValue] | "\(.[0])=\(.[1])"' ${PARAMETERS_FILE})) - aws cloudformation deploy --template-file /codebuild/output/packaged.yaml --region us-east-2 --stack-name InitialSetup --capabilities CAPABILITY_IAM --parameter-overrides ${PARAMS[@]}
如果通过 cli 进行测试,此解决方法效果很好。我还在容器内尝试了此解决方法,因为 buildspec.yaml 文件在后台创建了一个容器,其中 运行 执行这些命令,但代码构建不执行 aws cloudformation 部署步骤并失败。我收到错误 "aws: error: argument --parameter-overrides: expected at least one argument" 。我什至尝试在 shell 脚本中复制解决方法的两个步骤,然后执行它,但我 运行 进入错误“[Container] 2020/01/21 09:19:14 阶段上下文状态代码:COMMAND_EXECUTION_ERROR 消息:执行命令时出错:./test.sh。原因:退出状态 255" 有人可以在这里指导我吗?我的 buildspec.yaml 文件如下:
''' 版本:0.2
阶段: 安装: 运行时间版本: java: corretto8 命令:
- wget -O jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
- chmod +x ./jq
- cp jq /usr/bin
- jq --version
pre_build: 命令: # - echo "[预构建阶段]
构建: 命令:
- aws cloudformation package --template-file master.yaml --s3-bucket rtestbucket --output-template-file packaged.yaml
- aws s3 cp ./packaged.yaml s3://rtestbucket/packaged.yaml
- aws s3 cp s3://rtestbucket/packaged.yaml /codebuild/output
post_build: 命令:
- PARAMETERS_FILE="parameters.json" && PARAMS=($(jq -r '.Parameters[] | [.ParameterKey, .ParameterValue] | "\(.[0])=\(.[1])"' ${PARAMETERS_FILE}))
- ls
- aws cloudformation deploy --template-file /codebuild/output/packaged.yaml --region us-east-2 --stack-name InitialSetup --capabilities CAPABILITY_IAM --parameter-overrides ${PARAMS[@]}
工件: 类型:邮编 文件: - packaged.yaml
表达式 ${PARAMS[@]}
没有返回任何值,这导致错误 aws: error: argument --parameter-overrides: expected at least one argument
。查看代码并解决或删除该参数。
CodeBuild buildspec 命令在 bash shell 中不是 运行 我认为语法:
${PARAMS[@]}
... 是 bash 具体的。
根据这里的回答:
Try to wrap your commands in a script file with a shebang specifying the shell you'd like the commands to execute with.
我能够通过执行 shell 脚本中的所有必需步骤并提供对脚本的访问来解决此问题。