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

Corrupted stack - re-push from client

Open JoeMcMahon87 opened this issue 7 years ago • 10 comments

I had a problem with a Cognito resource and somehow my local code got out of sync with the pushed version. I ended up deleting the stack on the AWS account and cleared out the resources. Is there a way to re-push from the local? I fear that an 'amplify init' reset what I've already configured locally.

Any recommendations on best way to recover?

JoeMcMahon87 avatar Dec 05 '18 22:12 JoeMcMahon87

Could you clarify the following

  1. What version of amplify are you using
  2. Did you manage to remove all the resources (like s3, Cognito and IAM resources). Sometimes if your bucket has some content, deleting stack does not remove the bucket

yuth avatar Dec 05 '18 22:12 yuth

v0.1.27

Yep, removed everything via AWS console by deleting the stack, then manually cleaning up what the stack(s) couldn't do (were out of sync with). For example, I had set the domain on my user pool and the stack couldn't delete it with that set.

Maybe another way to describe what I want to do is: if I start with a clean AWS account and a clone of my git repo that has the amplify backend and my app code (React), how can I run it? amplify init wants to recreate most of what exists in the paramters/api-params files...

JoeMcMahon87 avatar Dec 05 '18 23:12 JoeMcMahon87

You could try these steps manually to recover. ymmv based on how cleanly the stack was deleted.

  1. Create a new project by running amplify init in a new folder
  2. Once the init succeeds, copy everything in the amplify/#current-cloud-backend of your corrupted project to backend of the new project you just created.
  3. Open amplify/backend/amplify-meta.json of the newly created project
  4. copy the json data under the key providers from amplify/#current-cloud-backend/amplify-meta.json from the newly created project and paste it on to amplify/backend/amplify-meta.jsons providers section
  5. Do an amplify push

yuth avatar Dec 05 '18 23:12 yuth

Closing the issue. Re-open if the recovery step didn't work

yuth avatar Dec 10 '18 18:12 yuth

This isn't resolved. Still getting Project stack doesn't exist

dyangelo-grullon avatar Oct 21 '19 02:10 dyangelo-grullon

Chiming in here in case anyone else runs into this: the CloudFormation details are scattered in a lot of places, it's best to just rename your ./amplify folder (maybe ./amplify-old) and run amplify init again within your project and walk through the prompts to set up a new stack. Then amplify add <service> again for the various services. If you are using API/GraphQL, re-add your schemas when prompted (from your backup). amplify push when you're done to rebuild the stack.

aaronfay avatar Nov 27 '19 18:11 aaronfay

I follow the below steps to tear down my environment on AWS, whilst keeping my local code intact. Basically, I just delete the current environment I'm on, and re-create it.

  1. Delete the aws-export.js file so it doesn't cause issues when we re-create our environment. You may want to back it up.

  2. Create & switch to a temporary environment (called temp) before we can delete the current one. We can do this by running the below command:

    amplify init
    

    Answer the following for the prompt:

    ? Do you want to use an existing environment? (Y/n) ---> n
    ? Enter a name for the environment ---> temp
    # ... The rest can be left as default
    
  3. (Optional) After running amplify init, it'd switch you to the new environment. You can check your list of environments, and the currently checked out environment via the amplify env list command.

  4. Remove the existing environment with the below command. This would remove the associated cloud resources as well.

    amplify env remove <YourEnvironmentName>
    

    <YourEnvironmentName> should be replaced by whatever your environment is. By default, it's dev.

  5. Now that the environment is deleted, run the below command to re-create it.

    amplify init
    

    Answer the following for the prompt:

    ? Do you want to use an existing environment? (Y/n) ---> n
    ? Enter a name for the environment ---> dev (or whatever the name is the environment you've deleted)
    # ... The rest can be left as default
    
  6. Now that we're switched back to our original environment & deleted the cloud resources, we can remove the temporary environment.

    amplify env remove temp
    
  7. Finally, we push the cloud resources for our environment so our AWS resources is re-created.

    amplify push
    

deltoss avatar Sep 06 '20 05:09 deltoss

Hit this today, my mental model of what is safe to do and what isn't just isn't solid enough in my head yet and its frustrating that I only seem to find out the boundaries when I hit them. A warning site or a helping hand to pull be back from the brink would be nice. As a result I think the CLI needs strengthening to make it safer to experiment, do stupid stuff for stupid people like me.

In my case I deleted some tables from DynamoDB which I'd removed from my schema but hadn't yet pushed those changes.

Misunderstanding No. 1: I thought that if I removed (or renamed) a table from the schema it wouldn't delete it in DynamoDB as that would be a destructive action, I could be losing data. I understood it that I would have to go in and clean up by hand. Is that not the case anymore? In this case I didn't care about losing data so deleted the table manually.

Misunderstanding No. 2: That if Amplify can't find a table when pushing (that it doesn't need anymore so shouldn't really care) it could just skip it (with a warning "Hey, I wanted to delete this for you but it appears to already be gone!"). Instead it just blows up and cancels the whole push and leaves me in an unknown state.

This is frustrating when developing but also adds to the terror in your belly about when this stuff goes live. Sure we fly a bit fast and loose in dev mode but I would like to think I can get it back up and running easily if something went wrong in production but having to do the "config/init shuffle!" described by @deltoss above doesn't really fill me with the warm fuzzies in my belly...more likely to bring me out in a cold sweat.

Currently when I've messed up my schema and get the dreaded red lines of doom when I push its difficult to know how to even begin to get back to known state. Need a way to safely "put it right" without having to resort to the "init shuffle".

PeteDuncanson avatar Nov 27 '20 15:11 PeteDuncanson

Old thread, but FWIW, I made the mistake of changing the custom name of a resource and compounded it by deleting stacks. I found a simple solution to restoring the stacks - I created a new environment 'amplify env add ' which allowed me to do a full push and restore a working environment with all necessary stacks. I'm not even sure the push was even necessary - just needed a new environment from which to delete the old one and recreated using 'env add' again. Everything fixed. Of course, you do delete all of your resources, but way easier than going the full 'init', 'add', 'add' route to recreate the app.

gbumgard avatar Jan 23 '21 08:01 gbumgard

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

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

github-actions[bot] avatar May 25 '21 07:05 github-actions[bot]