title: Getting AlreadyExistsException error while trying to create/update bash script for Cloudformation
body: <p>HI Am trying to write a bash for quickly creating/updating new stack for my deployment creation works fine but for the same when I try to update the stack am getting below error
  <em>An error occurred (AlreadyExistsException) when calling the CreateStack operation: Stack [Test-stack] already exists</em></p>
  <p>BASH script below</p>
  <pre><code>    #!/usr/bin/env bash
  
  usage=&quot;Usage: $(basename &quot;$0&quot;) 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
  &quot;
  
  if [ &quot;$1&quot; == &quot;-h&quot; ] || [ &quot;$1&quot; == &quot;--help&quot; ] || [ &quot;$1&quot; == &quot;help&quot; ] || [ &quot;$1&quot; == &quot;usage&quot; ] ; then
    echo &quot;$usage&quot;
    exit -1
  fi
  
  if [ -z &quot;$1&quot; ] || [ -z &quot;$2&quot; ] || [ -z &quot;$3&quot; ] ; then
    echo &quot;$usage&quot;
    exit -1
  fi
  
  shopt -s failglob
  set -eu -o pipefail
  
  echo &quot;Checking if stack exists ...&quot;
  
  if ! aws cloudformation describe-stacks --region $1 --stack-name $2 ; then
  
    echo -e &quot;\nStack does not exist, creating ...&quot;
    aws cloudformation create-stack \
      --region $1 \
      --stack-name $2 \
      ${@:3}
  
    echo &quot;Waiting for stack to be created ...&quot;
    aws cloudformation wait stack-create-complete \
      --region $1 \
      --stack-name $2 \
  
  else
  
    echo -e &quot;\nStack exists, attempting update ...&quot;
  
    set +e
    update_output=$( aws cloudformation update-stack \
      --region $1 \
      --stack-name $2 \
      ${@:3}  2&gt;&amp;1)
    status=$?
    set -e
  
    echo &quot;$update_output&quot;
  
    if [ $status -ne 0 ] ; then
  
      # Don't fail for no-op update
      if [[ $update_output == *&quot;ValidationError&quot;* &amp;&amp; $update_output == *&quot;No updates&quot;* ]] ; then
        echo -e &quot;\nFinished create/update - no updates to be performed&quot;
        exit 0
      else
        exit $status
      fi
  
    fi
  
    echo &quot;Waiting for stack update to complete ...&quot;
    aws cloudformation wait stack-update-complete \
      --region $1 \
      --stack-name $2 \
  
  fi
  
  echo &quot;Finished create/update successfully!&quot;
  </code></pre>