Amplify-cli: "amplify remove env" fails with "Cannot read property 'message' of null"

Created on 28 Jul 2020  Â·  10Comments  Â·  Source: aws-amplify/amplify-cli

Describe the bug
I have multiple environments. Most of them are in the same account / profile (called 'dev'). I have created one with a different profile (called 'test'). When I try and remove that I get

amplify env remove testse       
Scanning for plugins...
Plugin scan successful
? Are you sure you want to continue? This CANNOT be undone. (This would delete 'testse' environment of the project from the cloud) Yes
â ‹ Deleting resources from the cloud. This may take a few minutes...
Deleting env:testse
â ¸ Deleting resources from the cloud. This may take a few minutes...
Error in deleting env:testse
✖ remove env failed: Cannot read property 'message' of null
Cannot read property 'message' of null
TypeError: Cannot read property 'message' of null
    at AmplifyToolkit.removeEnvFromCloud [as _removeEnvFromCloud] (/usr/local/lib/node_modules/@aws-amplify/cli/src/extensions/amplify-helpers/remove-env-from-cloud.js:22:26)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at Object.run (/usr/local/lib/node_modules/@aws-amplify/cli/src/commands/env/remove.js:44:11)
    at Object.run (/usr/local/lib/node_modules/@aws-amplify/cli/src/commands/env.js:27:9)
    at Object.executeAmplifyCommand (/usr/local/lib/node_modules/@aws-amplify/cli/src/index.ts:161:3)
    at executePluginModuleCommand (/usr/local/lib/node_modules/@aws-amplify/cli/src/execution-manager.ts:161:3)
    at Object.executeCommand (/usr/local/lib/node_modules/@aws-amplify/cli/src/execution-manager.ts:25:5)
    at Object.run (/usr/local/lib/node_modules/@aws-amplify/cli/src/index.ts:84:5)

I tried this multiple times with the same response. Removing an environment on the profile 'dev' works.

 amplify env remove develop
? Are you sure you want to continue? This CANNOT be undone. (This would delete 'develop' environment of the project from the cloud) Yes
â ‹ Deleting resources from the cloud. This may take a few minutes...
Deleting env:develop
✔ Successfully removed environment from the cloud
Successfully removed environment from your project locally

I guess this has something to do with some profile being saved wrongly in an autogenerated file?

Amplify CLI Version
4.24.3 and 4.25.0

To Reproduce
I have not tried but I assume:

amplify init with aws 'devProfile'
amplify push
git checkout -b test
amplify init with aws 'testProfile'
amplify push

amplify env checkout dev
amplify env remove test

Expected behavior
Expecting it to remove the environment or at least tell me what the error is.

Desktop (please complete the following information):

  • OS: Mac 10.15.5
  • Node Version. v14.4.0
bug multienv platform

Most helpful comment

As @bolenc explain this is because the environment checked out use a profile different than the environment you are trying to delete.
Just edit the file amplify/.config/local-aws-info.json and temporarily change the value profile of the current env to the one you need to use for deletion.
Once done the command amplify env remove XXX will work.

_That being said it is not convenient for the users and the Amplify team should make the fix automatic._

All 10 comments

@Zanndorin could you confirm if the deployment bucket for the environment still exists?

"testse" deployment bucket exists (in test account).

Same problem here.
Bucket also exists in the account

I found that I get this error when the environment I'm trying to remove is on a different account than the currently active environment. As a workaround, you can check out (or create) an environment on the same account as the one being removed.

As @bolenc explain this is because the environment checked out use a profile different than the environment you are trying to delete.
Just edit the file amplify/.config/local-aws-info.json and temporarily change the value profile of the current env to the one you need to use for deletion.
Once done the command amplify env remove XXX will work.

_That being said it is not convenient for the users and the Amplify team should make the fix automatic._

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

I was told by our AWS solutions architect that current best practice is to use multiple accounts (one per developer, one for production etc) so this is really inconvenient when following that.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Hey bot, this issue is still occuring

I will mark this as a bug the CLI needs to switch profiles automatically for the corresponding environment,

Was this page helpful?
0 / 5 - 0 ratings