Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment AlreadyExistsException #2096

Closed
4 tasks done
adi518 opened this issue Jul 27, 2021 · 4 comments
Closed
4 tasks done

Environment AlreadyExistsException #2096

adi518 opened this issue Jul 27, 2021 · 4 comments
Labels
archived This issue has been locked.

Comments

@adi518
Copy link

adi518 commented Jul 27, 2021

Before opening, please confirm:

App Id

dazj4he0xk1lv

Region

us-east-1

Amplify Console feature

Backend builds, E2E tests, Previews

Describe the bug

Amplify backend build doesn't find an existing environment and throws an AlreadyExistsException exception. I can't do subsequent builds in Previews and now it even popped on a feature branch, since I alternated to that from Previews.

Expected behavior

Find the existing environment, namely the environment that was created on the initial deployment.

Reproduction steps

It seems intermittent with the branch autodetection feature, but with Previews it happens consistently and it's probably the same bug.

  1. Enable Previews
  2. Create a Pull Request
  3. Verify the first build is successful
  4. Push another commit and watch the build fail

Build Settings

version: 1
backend:
  phases:
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - amplifyPush --simple
frontend:
  phases:
    preBuild:
      commands:
        - yarn install
    build:
      commands:
        - yarn build

  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

Log output

# Put your logs below this line

                                 # Initializing new Amplify environment: prch (amplify init)
2021-07-20T11:40:51.826Z [INFO]: �[33mNote: It is recommended to run this command from the root of your app directory�[39m
2021-07-20T11:40:58.271Z [WARNING]: - Initializing project in the cloud...
2021-07-20T11:40:58.342Z [INFO]: �[31m�[39m
                                 �[31mAn error occurred when creating the CloudFormation stack�[39m
2021-07-20T11:40:58.344Z [WARNING]: ✖ Root stack creation failed
2021-07-20T11:40:58.349Z [INFO]: �[0mAlreadyExistsException: Stack [amplify-deepdubapp-prch-103126] already exists�[0m
                                 �[0m    at Request.extractError (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/protocol/query.js:50:29)�[0m
                                 �[0m    at Request.callListeners (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/sequential_executor.js:106:20)�[0m
                                 �[0m    at Request.emit (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/sequential_executor.js:78:10)�[0m
                                 �[0m    at Request.emit (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/request.js:688:14)�[0m
                                 �[0m    at Request.transition (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/request.js:22:10)�[0m
                                 �[0m    at AcceptorStateMachine.runTo (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/state_machine.js:14:12)�[0m
                                 �[0m    at /root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/state_machine.js:26:10�[0m
                                 �[0m    at Request.<anonymous> (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/request.js:38:9)�[0m
                                 �[0m    at Request.<anonymous> (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/request.js:690:12)�[0m
                                 �[0m    at Request.callListeners (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/sequential_executor.js:116:18)�[0m
                                 �[0m    at Request.emit (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/sequential_executor.js:78:10)�[0m
                                 �[0m    at Request.emit (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/request.js:688:14)�[0m
                                 �[0m    at Request.transition (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/request.js:22:10)�[0m
                                 �[0m    at AcceptorStateMachine.runTo (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/state_machine.js:14:12)�[0m
                                 �[0m    at /root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/state_machine.js:26:10�[0m
                                 �[0m    at Request.<anonymous> (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/request.js:38:9)�[0m
                                 �[0m    at Request.<anonymous> (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/request.js:690:12)�[0m
                                 �[0m    at Request.callListeners (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/sequential_executor.js:116:18)�[0m
                                 �[0m    at callNextListener (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/sequential_executor.js:96:12)�[0m
                                 �[0m    at IncomingMessage.onEnd (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/event_listeners.js:336:13)�[0m
                                 �[0m    at IncomingMessage.emit (events.js:326:22)�[0m
                                 �[0m    at IncomingMessage.EventEmitter.emit (domain.js:483:12)�[0m
                                 �[0m    at endReadableNT (_stream_readable.js:1241:12)�[0m
                                 �[0m    at processTicksAndRejections (internal/process/task_queues.js:84:21) {�[0m
                                 �[0m  code: 'AlreadyExistsException',�[0m
                                 �[0m  time: 2021-07-20T11:40:58.341Z,�[0m
                                 �[0m  requestId: '1430a38b-6591-4d65-98bc-5ea580fc3f03',�[0m
                                 �[0m  statusCode: 400,�[0m
                                 �[0m  retryable: false,�[0m
                                 �[0m  retryDelay: 30.883168292505147�[0m
                                 �[0m}�[0m
2021-07-20T11:40:58.365Z [ERROR]: !!! Build failed
2021-07-20T11:40:58.366Z [ERROR]: !!! Non-Zero Exit Code detected

Additional information

No response

@adi518 adi518 changed the title environment AlreadyExistsException Environment AlreadyExistsException Jul 27, 2021
@adi518
Copy link
Author

adi518 commented Jul 28, 2021

I initially started this issue: #2074, but for the sake of deduplicating I closed it in favor of this, which is more explicit. Unfortunately, there's at least 4-5 more related issues: https://github.com/aws-amplify/amplify-console/issues?q=is%3Aissue+is%3Aopen+environment+exist+.

For the time being, I worked around it by ditching envCache --get stackInfo and getting the stack info through AWS CLI.

  1. Grab amplifyPush.sh: https://github.com/aws-amplify/amplify-console/blob/master/scripts/amplifyPush.sh and place it at the root of your app.
  2. Update amplify.yml to use ./amplifyPush.sh instead of the default amplifyPush and install jq.
backend:
  phases:
    preBuild:
      commands:
        - yum update --assumeyes
        - yum install --assumeyes jq
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - chmod u+x ./amplifyPush.sh
        - ./amplifyPush.sh --simple
  1. Remove lines 119-120 and replace with the following snippet:
# https://docs.amplify.aws/cli/teams/commands#import-an-environment
echo "# Getting Amplify CLI Cloud-Formation stack info from environment cache"
BACKEND_ENV="$(aws amplify get-backend-environment --app-id ${AWS_APP_ID} --environment-name ${ENV} || true)"
if [[ ${BACKEND_ENV} ]];
then
    STACKNAME="$(echo ${BACKEND_ENV} | jq --raw-output '.backendEnvironment.stackName')"
    STACKINFO=$(aws cloudformation describe-stacks --stack-name ${STACKNAME} | jq '.Stacks[0]')
    STACKINFO=$(echo ${STACKINFO} | jq '.Outputs | reduce .[] as $item ({}; .[$item.OutputKey] = $item.OutputValue)')
    STACKINFO="{\
        \"awscloudformation\":$STACKINFO\
    }"
fi
export STACKINFO

@adi518
Copy link
Author

adi518 commented Aug 17, 2021

I found out envCache is actually working, but it has a fatal bug, as it lowercases the key that's passed to it, therefore when it tries to get the default variable (envCache --get stackInfo), it fails! Not only that, it seems the default variable name gets overridden at an empty value, rendering it useless. It's such a critical issue that it should be prioritised ASAP.

@ghost
Copy link

ghost commented May 25, 2022

The fix for this bug has been deployed. Please re-open if this behavior persists. Thank you!

@ghost ghost closed this as completed May 25, 2022
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot added the archived This issue has been locked. label Oct 28, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived This issue has been locked.
Projects
None yet
Development

No branches or pull requests

1 participant