验证错误:在 Cloudformation 中不执行任何更新返回错误

问题描述 投票:0回答:3

当我在 CI aws-cli 中执行以更新 CloudFormation 堆栈时,我收到以下错误消息:

An error occurred (ValidationError) when calling the UpdateStack operation: No updates are to be performed.

没有看到任何更新,就像错误一样,因此 CI 失败。知道如何捕获此错误吗?

amazon-web-services aws-cli
3个回答
7
投票

--no-fail-on-empty-changeset
与您的 aws cli 命令一起使用。

例如:

aws cloudformation deploy --template-file ${TEMPLATE_FILE_PATH} --stack-name ${CF_STACK_NAME} --parameter-overrides ${PARAMETER_OVERRIDES} --no-fail-on-empty-changeset


5
投票

不幸的是,命令

aws cloudformation update-stack
没有选项:
--no-fail-on-empty-changeset

但是,也许这样的东西可以工作:

#!/bin/bash

output=$(aws cloudformation update-stack --stack-name foo 2>&1)

RESULT=$?

if [ $RESULT -eq 0 ]; then
  echo "$output"
else
  if [[ "$output" == *"No updates are to be performed"* ]]; then
    echo "No cloudformation updates are to be performed."
    exit 0
  else
    echo "$output"
    exit $RESULT
  fi
fi

0
投票

对于解决方案#5,我们需要将output=$(aws cloudformation update-stack --stack-name foo 2>&1)放在if语句中,否则该语句将返回非零代码,并且shell将退出

我的增强版:

#!/bin/bash

if output=$(aws cloudformation update-stack --stack-name foo 2>&1)
then
  echo "$output"
else
  RESULT=$?
  echo $output
  if [[ "$output" == *"No updates are to be performed"* ]]; then
    echo "No cloudformation updates are to be performed."
    exit 0
  else
    exit $RESULT
  fi
fi
© www.soinside.com 2019 - 2024. All rights reserved.