我正在尝试在 AWS Cloudformation CLI 中编写一个通用脚本,它将堆栈的参数 AMI 更新为新值,同时保留其余参数不变。
到目前为止,我尝试这样做:
aws cloudformation update-stack --stack-name asg-xxx-123 --use-previous-template --parameters ParameterKey=ApplicationName,UsePreviousValue=true ParameterKey=ArtefactVersion,UsePreviousValue=true ParameterKey=MachineImage,ParameterValue=ami-123
请注意,有 2 个参数仅使用 UsePreviousValue=true
并且只有 ParameterKey=MachineImage
的值是需要改变的 - 这很好用。
但是,由于我需要它成为通用脚本,如何处理某些堆栈具有比上面更多参数的情况(或者甚至有些堆栈具有不同的参数但仍然具有 ParameterKey=MachineImage
)?有没有办法说只改变 ParameterKey=MachineImage
的值其余的都应该使用以前的值,而无需在 --parameters
中明确列出?
最佳答案
我能够使用 aws cli 编写 unix 脚本,如下所示:
curdate=`date +"%Y-%m-%d"`
newami=${1}
for sname in $(aws cloudformation describe-stacks --query "Stacks[?contains(StackName,'prefix-') ].StackName" --output text) ;
do
paramslist="--parameters ";
for paramval in $(aws cloudformation describe-stacks --stack-name $sname --query "Stacks[].Parameters[].ParameterKey" --output text) ;
do
if [ $paramval == "MachineImg" ] || [ $paramval == "AMI" ]
then
paramslist+="ParameterKey=${paramval},ParameterValue=${newami} "; #use the ami from args
else
paramslist+="ParameterKey=${paramval},UsePreviousValue=true "; #else keep using UsePreviousValue=true
fi
done
printf "aws cloudformation update-stack --stack-name ${sname} --use-previous-template ${paramslist};\n" >> "/tmp/ami-update-${curdate}.sh"
done
这会生成一个新的 .sh 文件,其中包含更新命令,然后我查看生成的 .sh 的内容并创建一个源来执行这些命令:
source ./ami-update-2020-08-17.sh
关于amazon-web-services - 有没有办法使用 aws cloudformation 更新堆栈仅指定更改的参数,并避免对未更改的参数显式使用 UsePreviousValue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61887550/
相关文章:
javascript - 谷歌邮箱 : Button/Link which trigger a sc
python - 我怎样才能看到 Pandas 的几个最大值?
python - 在对数刻度上生成均匀间隔的值(如 `np.linspace()` ,但在对数刻度上
python - matplotlib 为单个散点图添加具有多个条目的图例
amazon-web-services - CognitoIdentityCredentials 不
scala - 为什么在使用 List 时得到的结果与使用 Tuple 时得到的结果不同?
python - 类型错误 : get_bind() got an unexpected keywo