amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Allow unlinking a Amplify added auth resource

Open DuncanHouston opened this issue 3 years ago • 6 comments

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

No response

Amplify CLI Version

10.6.2

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No manual changes

Describe the bug

I successfully implemented a new user pool with migration from the old pool in a development environment. I used the CLI to "amplify remove auth", but when I could not push the changes, I read that I needed to "amplify update API" which I did, and then successfully did "amplify push". Migration was working successfully with the old and new pools.

However, when merging the changes and doing an "amplify push" in the production environment, this initially didn't work. After I did an "amplify update api" as I did in the dev environment, followed by an "amplify push", it worked. Only difference - in the production environment, Amplify decided to delete the user pool!

The above happened despite the fact that the docs clearly state they will not delete the Cognito resource, and the fact that this didn't happen in the development environment.

What's worse is there is no standard way to backup a Cognito user pool.

Please AWS / Amplify team, can you restore the user pool?

Expected behavior

I expected the CLI to detach from, but not delete, the old user pool.

Reproduction steps

I haven't tried to replicate this yet, however these should be the steps:

  1. Setup a development and production environment with GraphQL and Auth
  2. In the development environment, "amplify remove auth", then "amplify update api" and "amplify push"
  3. Switch branches (in my case in git), merge changes, and run "amplify update api" and "amplify push"

Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • [X] I have removed any sensitive information from my code snippets and submission.

DuncanHouston avatar Feb 05 '23 15:02 DuncanHouston

I have the old (deleted) user pool ID, for what that's worth :(

DuncanHouston avatar Feb 05 '23 15:02 DuncanHouston

Hey @DuncanHouston, thank you for reaching out. From the reproduction steps provided

In the development environment, "amplify remove auth", then "amplify update api" and "amplify push"

i observed the amplify remove auth was utilized. To better understand this issue could you provide us some additional information on your use case and information on the migration? Additionally, I wanted to provide some information when removing an Amplify auth resource. When running an amplify remove auth on a Amplify CLI created auth using amplify add auth the user pool will be deleted. When running an amplify remove auth on a Amplify CLI imported auth using amplify import auth the user pool will only be unlinked.

ykethan avatar Feb 06 '23 17:02 ykethan

Hi @ykethan

Thanks for the reply. OK, the background is that we needed to migrate the user pool from using email address as a username, to a regular username. So, I wanted to unlink, but not delete the current user pool, and then implement a migration process - which worked (in dev). The documentation clearly states that the underlying user pool will not be deleted when you do amplify remove auth. See here: https://docs.amplify.aws/cli/auth/import/#unlink-an-existing-cognito-user-pool-or-identity-pool

And indeed, in the dev environment, this happened. (Note, that the initial Auth would almost certainly have been added with amplify add auth, as we did not link / import existing resources) Initially, after doing the amplify remove auth, I could not push. It failed with "Resource is not in the state stackUpdateComplete". After searching here, I read that I needed to do amplify update api, which I did, and which worked. I think that was to link up a new Auth, which was required for the schema to work.

Then came the catastrophic merge into prod branch, and deploy. Initially I tried to do this using the automated build process pulling from a git repo, but that failed, as they often seem to with major changes. So I thought OK, time for the CLI. So I did amplify env checkout prod, and tried to push from there. No joy. So I tried amplify update api, which did work - but at the cost of killing my user pool. In hindsight, I'm thinking that after checking out the prod branch, I should have run amplify remove auth first, before amplify update cli.

So, I take it there is no way to recover the user pool? The AWS Cognito team doesn't create backups of critical data like authentication data, and keep a copy say for a month? (I mean, it's not like they provide a means of publicly backing up).

Surely the default here should be to not kill the Cognito resource? Unlink, but not delete. Most things in the console have protection in place - e.g. type "delete", or "delete resource-name". Not so with Amplify CLI, which is a mistake I feel.

I'm really hoping the pool is recoverable, but thinking that's a complete crap shoot.

Either way, I'd suggest not killing the resource, especially one that can't be backed up.

DuncanHouston avatar Feb 06 '23 21:02 DuncanHouston

Hey @DuncanHouston, thank you for the feedback. I would definitely agree that the destructive update should notify the user more explicitly. unfortunately, the deleted user pool cannot be recovered from Amplify. As only an imported Cognito resource will be unlinked on a amplify remove auth. I would also suggest reaching out to the AWS Cognito support team for additional information/possibilities on recovering a user pool.

I will be marking this as a feature request.

ykethan avatar Feb 08 '23 14:02 ykethan

Hi @ykethan

Thanks for clarifying. 2 quick points:

  1. When I used amplify remove auth in the dev environment, even though my pool was not created using amplify import auth, the pool was only unlinked and not deleted. This was consistent with the documentation
  2. If you're saying that the expected behaviour is that it will delete the pool, the you need to update the documentation

DuncanHouston avatar Feb 09 '23 09:02 DuncanHouston

Hey @DuncanHouston, thank you for following up. I'm unable able to reproduce the issue where amplify remove auth does not delete the Cognito User Pool. Is deletion protection enabled for this resource? How was the Cognito resource originally created (e.g. amplify add auth)?

ykethan avatar Feb 09 '23 15:02 ykethan