linux - 尝试为 Cloudformation 创建/更新 bash 脚本时出现 AlreadyExistsException 错误
问题描述
嗨我正在尝试编写一个 bash 来快速创建/更新我的部署创建的新堆栈工作正常,但是当我尝试更新堆栈时,我得到以下错误 调用 CreateStack 操作时发生错误(AlreadyExistsException):堆栈 [测试-stack] 已经存在
下面是 BASH 脚本
#!/usr/bin/env bash
usage="Usage: $(basename "$0") region stack-name [aws-cli-opts]
where:
region - the AWS region
stack-name - the stack name
aws-cli-opts - extra options passed directly to create-stack/update-stack
"
if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ "$1" == "help" ] || [ "$1" == "usage" ] ; then
echo "$usage"
exit -1
fi
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] ; then
echo "$usage"
exit -1
fi
shopt -s failglob
set -eu -o pipefail
echo "Checking if stack exists ..."
if ! aws cloudformation describe-stacks --region $1 --stack-name $2 ; then
echo -e "\nStack does not exist, creating ..."
aws cloudformation create-stack \
--region $1 \
--stack-name $2 \
${@:3}
echo "Waiting for stack to be created ..."
aws cloudformation wait stack-create-complete \
--region $1 \
--stack-name $2 \
else
echo -e "\nStack exists, attempting update ..."
set +e
update_output=$( aws cloudformation update-stack \
--region $1 \
--stack-name $2 \
${@:3} 2>&1)
status=$?
set -e
echo "$update_output"
if [ $status -ne 0 ] ; then
# Don't fail for no-op update
if [[ $update_output == *"ValidationError"* && $update_output == *"No updates"* ]] ; then
echo -e "\nFinished create/update - no updates to be performed"
exit 0
else
exit $status
fi
fi
echo "Waiting for stack update to complete ..."
aws cloudformation wait stack-update-complete \
--region $1 \
--stack-name $2 \
fi
echo "Finished create/update successfully!"
解决方案
当我没有该describe-stacks
功能的权限时,似乎可以触发此错误。检查您的权限以运行它。
由于没有权限,它会进入创建堆栈逻辑。
推荐阅读
- java - 如何使用一个电子邮件 ID 相同的 sql 查询从多个表中删除一行
- javascript - 将参数传递给 Firebase 云函数
- python - 如何更改机器人日志/报告文件的名称和文件夹?
- react-native - webview成功加载vue native中的url后调用方法
- php - 在 PHP 5.3 中使用 opendir() 打开目录失败,具有 777 文件夹权限
- dart - 关于使用 Dart 编码
- rust - 我对静态特征界限的理解是否正确?
- php - 当我的用户代理不包含类似的东西时,如何使用 php 检测用户使用 ipad
- c# - .NET Core 依赖注入解决问题
- sql - with (nolock) in hive 等价于 sql (nolock)