gpt4 book ai didi

linux - 尝试为 Cloudformation 创建/更新 bash 脚本时出现 AlreadyExistsException 错误

转载 作者:行者123 更新时间:2023-12-03 07:31:06 24 4
gpt4 key购买 nike

嗨,我正在尝试编写一个 bash 来快速创建/更新新堆栈,以便我的部署创建工作正常,但当我尝试更新堆栈时,出现以下错误调用CreateStack操作时发生错误(AlreadyExistsException):Stack [Test-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 函数的权限时,似乎可以触发此错误。检查您运行此程序的权限。

由于没有权限,它进入创建堆栈逻辑。

关于linux - 尝试为 Cloudformation 创建/更新 bash 脚本时出现 AlreadyExistsException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62997545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com