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

Moving from Dev to Prod - Error Fixing

Open sph94 opened this issue 1 year ago • 2 comments

Amplify CLI Version

12.12.0

Question

I am using amplify (cognito, dynamodb, appsync, lambda, hosting) for a web app with nextjs using github. Similar to this thread I am looking to move from my dev env to prod. I want to copy all settings across from dev and not have to build from scratch.

My first issue is that I have made the error of creating the new prod env and then running amplify pull rather than the amplify push that I believe I should have made. It is now marking everything for deletion when I run amplify status and I don't know how to undo this.

Secondly, once this is fixed what are the steps to moving each service across to prod? For example I know I need a new dynamodb table (my dev table was autocreated by appsync).

Terminal code below from accidental pull. All I had done prior to this is create the prod env.

myprofile@Macbook-Air project % amplify env check
out dev
⠇ Initializing your environment: dev⠋ Building res
⠋ Initializing your environment: dev
⠧ Initializing your environment: dev✅ GraphQL schema compiled successfully.

Edit your schema at /Users/myprofile/Dev/project/amplify/backend/api/project/schema.graphql or place .graphql files in a directory at /Users/myprofile/Dev/project/amplify/backend/api/project/schema
✔ Initialized provider successfully.
✅ Initialized your environment successfully.
myprofile@Macbook-Air project % amplify env check
out prod
⠋ Initializing your environment: prod⠋ Building re
⠙ Initializing your environment: prod
✅ GraphQL schema compiled successfully.

Edit your schema at /Users/myprofile/Dev/project/amplify/backend/api/project/schema.graphql or place .graphql files in a directory at /Users/myprofile/Dev/project/amplify/backend/api/project/schema
✔ Initialized provider successfully.
✅ Initialized your environment successfully.
myprofile@Macbook-Air project % amplify pull

Pre-pull status:

    Current Environment: prod
    
┌──────────┬──────────────────────────────────────┬───────────┬───────────────────┐
│ Category │ Resource name                        │ Operation │ Provider plugin   │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Api      │ project                              │ Create    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ projecta92c9f8                      │ Create    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ userPoolGroups                       │ Create    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Function │ S3Trigger283da0e                    │ Create    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Function │ projecta9c29f8CustomMessage         │ Create    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Function │ projecta22c29f4DefineAuthChallenge   │ Create    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Storage  │ ProjectTable                         │ Create    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Storage  │ mainBucket                           │ Create    │ awscloudformation │
└──────────┴──────────────────────────────────────┴───────────┴───────────────────┘

⚠️ Local changes detected.
⚠️ Pulling changes from the cloud will override your local       Update the e
? Are you sure you would like to continue? Yes
✔ Successfully pulled backend environment prod from the cloud.
✅ 
Post-pull status:

    Current Environment: prod
    
┌──────────┬───────────────┬───────────┬─────────────────┐
│ Category │ Resource name │ Operation │ Provider plugin │
└──────────┴───────────────┴───────────┴─────────────────┘

myprofile@Macbook-Air project % amplify env checkout dev
✔ Initialized provider successfully.
✅ Initialized your environment successfully.
myprofile@Macbook-Air project % amplify status

    Current Environment: dev
    
┌──────────┬──────────────────────────────────────┬───────────┬───────────────────┐
│ Category │ Resource name                        │ Operation │ Provider plugin   │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Api      │ project                              │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ projecta92c29f8                      │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ userPoolGroups                       │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Function │ S3Trigger423da0e                    │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Function │ projecta92c29f8CustomMessage         │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Function │ projecta92c2f8DefineAuthChallenge   │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Storage  │ ProjectTable                         │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Storage  │ mainBucket                           │ Delete    │ awscloudformation │
└──────────┴──────────────────────────────────────┴───────────┴───────────────────┘


myprofile@Macbook-Air project % git status
On branch testing
Your branch is up to date with 'origin/testing'.

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    amplify/backend/api/project/cli-inputs.json
        deleted:    amplify/backend/api/project/parameters.json
        deleted:    amplify/backend/api/project/resolvers/README.md
        deleted:    amplify/backend/api/project/schema.graphql
        deleted:    amplify/backend/api/project/stacks/CustomResources.json
        deleted:    amplify/backend/api/project/transform.conf.json
        deleted:    amplify/backend/auth/projecta92c29f8/cli-inputs.json
        deleted:    amplify/backend/auth/userPoolGroups/user-pool-group-precedence.json
        modified:   amplify/backend/backend-config.json
        deleted:    amplify/backend/function/S3Trigger4293da0e/S3Trigger4293da0e-cloudformation-template.json
        deleted:    amplify/backend/function/S3Trigger4293da0e/amplify.state
        deleted:    amplify/backend/function/S3Trigger4293da0e/src/event.json
        deleted:    amplify/backend/function/S3Trigger4293da0e/src/index.js
        deleted:    amplify/backend/function/S3Trigger4293da0e/src/package-lock.json
        deleted:    amplify/backend/function/S3Trigger4293da0e/src/package.json
        deleted:    amplify/backend/function/projecta92c29f8CustomMessage/amplify.state
        deleted:    amplify/backend/function/projecta92c29f8CustomMessage/custom-policies.json
        deleted:    amplify/backend/function/projecta92c29f8CustomMessage/function-parameters.json
        deleted:    amplify/backend/function/projecta92c29f8CustomMessage/parameters.json
        deleted:    amplify/backend/function/projecta92c29f8CustomMessage/projecta92c29f8CustomMessage-cloudformation-template.json
        deleted:    amplify/backend/function/projecta92c29f8CustomMessage/src/event.json
        deleted:    amplify/backend/function/projecta92c29f8CustomMessage/src/index.js
        deleted:    amplify/backend/function/projecta92c29f8CustomMessage/src/package-lock.json
        deleted:    amplify/backend/function/projecta92c29f8CustomMessage/src/package.json
        deleted:    amplify/backend/function/projecta92c29f8CustomMessage/src/verification-link.js
        deleted:    amplify/backend/function/projecta92c29f8DefineAuthChallenge/amplify.state
        deleted:    amplify/backend/function/projecta92c29f8DefineAuthChallenge/custom-policies.json
        deleted:    amplify/backend/function/projecta92c29f8DefineAuthChallenge/function-parameters.json
        deleted:    amplify/backend/function/projecta92c29f8DefineAuthChallenge/parameters.json
        deleted:    amplify/backend/function/projecta92c29f8DefineAuthChallenge/projecta92c29f8DefineAuthChallenge-cloudformation-template.json
        deleted:    amplify/backend/function/projecta92c29f8DefineAuthChallenge/src/boilerplate-define-challenge.js
        deleted:    amplify/backend/function/projecta92c29f8DefineAuthChallenge/src/event.json
        deleted:    amplify/backend/function/projecta92c29f8DefineAuthChallenge/src/index.js
        deleted:    amplify/backend/function/projecta92c29f8DefineAuthChallenge/src/package-lock.json
        deleted:    amplify/backend/function/projecta92c29f8DefineAuthChallenge/src/package.json
        deleted:    amplify/backend/storage/ProjectTable/cli-inputs.json
        deleted:    amplify/backend/storage/mainBucket/cli-inputs.json
        modified:   amplify/backend/types/amplify-dependent-resources-ref.d.ts

no changes added to commit (use "git add" and/or "git commit -a")
myprofile@Macbook-Air project % git reset --hard
HEAD is now at 787e3c6 more changes 27 may
myprofile@Macbook-Air project % git status
On branch testing
Your branch is up to date with 'origin/testing'.

nothing to commit, working tree clean
myprofile@Macbook-Air project % amplify env list

| Environments |
| ------------ |
| *dev         |
| prod         |

myprofile@Macbook-Air project % git status
On branch testing
Your branch is up to date with 'origin/testing'.

nothing to commit, working tree clean
myprofile@Macbook-Air project % amplify status

    Current Environment: dev
    
┌──────────┬──────────────────────────────────────┬───────────┬───────────────────┐
│ Category │ Resource name                        │ Operation │ Provider plugin   │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Api      │ project                              │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ projecta92c29f8                      │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ userPoolGroups                       │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Function │ S3Trigger4293da0e                    │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Function │ projecta92c29f8CustomMessage         │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Function │ projecta92c29f8DefineAuthChallenge   │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Storage  │ ProjectTable                         │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Storage  │ mainBucket                           │ Delete    │ awscloudformation │
└──────────┴──────────────────────────────────────┴───────────┴───────────────────┘


myprofile@Macbook-Air project % amplify env list

| Environments |
| ------------ |
| *dev         |
| prod         |

myprofile@Macbook-Air project % amplify pull

Pre-pull status:

    Current Environment: dev
    
┌──────────┬──────────────────────────────────────┬───────────┬───────────────────┐
│ Category │ Resource name                        │ Operation │ Provider plugin   │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Api      │ project                              │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ projecta92c29f8                      │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ userPoolGroups                       │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Function │ S3Trigger4293da0e                    │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Function │ projecta92c29f8CustomMessage         │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Function │ projecta92c29f8DefineAuthChallenge   │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Storage  │ ProjectTable                         │ Delete    │ awscloudformation │
├──────────┼──────────────────────────────────────┼───────────┼───────────────────┤
│ Storage  │ mainBucket                           │ Delete    │ awscloudformation │
└──────────┴──────────────────────────────────────┴───────────┴───────────────────┘

⚠️ Local changes detected.
⚠️ Pulling changes from the cloud will override your local changes.
? Are you sure you would like to continue? (y/N) N

sph94 avatar May 28 '24 08:05 sph94

I successfully restored the prior cloud state by running amplify pull --restore, given that I had never pushed the marked deletions to the cloud.

sph94 avatar May 28 '24 11:05 sph94

Hey @sph94, thank you for reaching out. I understand the pull shows the resources in delete status in the dev env, running amplify pull should pull the current-cloud-backend from the backend and should not remove the resources. The amplify status should show as no change. The running amplify env checkout prod should update the status to create in the new env. To simulate as follows

ykethan@b0be8349b8b1 ~/D/a/g/analyticsupdate> amplify status

    Current Environment: dev
    
┌──────────┬─────────────────────────────────┬───────────┬───────────────────┐
│ Category │ Resource name                   │ Operation │ Provider plugin   │
├──────────┼─────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ analyticsupdate140386fb140386fb │ No Change │ awscloudformation │
├──────────┼─────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ userPoolGroups                  │ No Change │ awscloudformation │
└──────────┴─────────────────────────────────┴───────────┴───────────────────┘


ykethan@b0be8349b8b1 ~/D/a/g/analyticsupdate> amplify add env prd
Note: It is recommended to run this command from the root of your app directory
Using default provider  awscloudformation
? Select the authentication method you want to use: AWS profile

For more information on AWS Profiles, see:
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html

? Please choose the profile you want to use default
Adding backend environment prd to AWS Amplify app: d2wxl0voodofz0

Deployment completed.
Deploying root stack analyticsupdate [ ---------------------------------------- ] 0/4
        amplify-analyticsupdate-prd-a… AWS::CloudFormation::Stack     CREATE_IN_PROGRESS             Wed May 29 2024 12:41:42…     
        AuthRole                       AWS::IAM::Role                 CREATE_IN_PROGRESS             Wed May 29 2024 12:41:45…     
        DeploymentBucket               AWS::S3::Bucket                CREATE_IN_PROGRESS             Wed May 29 2024 12:41:45…     
        UnauthRole                     AWS::IAM::Role                 CREATE_IN_PROGRESS             Wed May 29 2024 12:41:45…     

Deployment state saved successfully.
✔ Initialized provider successfully.
✅ Initialized your environment successfully.
✅ Your project has been successfully initialized and connected to the cloud!
Some next steps:

"amplify status" will show you what you've added already and if it's locally configured or deployed
"amplify add <category>" will allow you to add features like user login or a backend API
"amplify push" will build all your local backend resources and provision it in the cloud
"amplify console" to open the Amplify Console and view your project status
"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud


Pro tip:
Try "amplify add api" to create a backend API and then "amplify push" to deploy everything

ykethan@b0be8349b8b1 ~/D/a/g/analyticsupdate> amplify status

    Current Environment: prd
    
┌──────────┬─────────────────────────────────┬───────────┬───────────────────┐
│ Category │ Resource name                   │ Operation │ Provider plugin   │
├──────────┼─────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ analyticsupdate140386fb140386fb │ Create    │ awscloudformation │
├──────────┼─────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ userPoolGroups                  │ Create    │ awscloudformation │
└──────────┴─────────────────────────────────┴───────────┴───────────────────┘

                                                                                                                                                                     
ykethan@b0be8349b8b1 ~/D/a/g/analyticsupdate [SIGINT]> amplify pull

Pre-pull status:

    Current Environment: prd
    
┌──────────┬─────────────────────────────────┬───────────┬───────────────────┐
│ Category │ Resource name                   │ Operation │ Provider plugin   │
├──────────┼─────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ analyticsupdate140386fb140386fb │ Create    │ awscloudformation │
├──────────┼─────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ userPoolGroups                  │ Create    │ awscloudformation │
└──────────┴─────────────────────────────────┴───────────┴───────────────────┘

⚠️ Local changes detected.
⚠️ Pulling changes from the cloud will override your local changes.
? Are you sure you would like to continue? Yes
✔ Successfully pulled backend environment prd from the cloud.
✅ 
Post-pull status:

    Current Environment: prd
    
┌──────────┬───────────────┬───────────┬─────────────────┐
│ Category │ Resource name │ Operation │ Provider plugin │
└──────────┴───────────────┴───────────┴─────────────────┘

ykethan@b0be8349b8b1 ~/D/a/g/analyticsupdate> amplify status

    Current Environment: prd
    
┌──────────┬───────────────┬───────────┬─────────────────┐
│ Category │ Resource name │ Operation │ Provider plugin │
└──────────┴───────────────┴───────────┴─────────────────┘


ykethan@b0be8349b8b1 ~/D/a/g/analyticsupdate> amplify add env dev
Note: It is recommended to run this command from the root of your app directory
Using default provider  awscloudformation
✔ Initialized provider successfully.
✅ Initialized your environment successfully.
✅ Your project has been successfully initialized and connected to the cloud!
Some next steps:

"amplify status" will show you what you've added already and if it's locally configured or deployed
"amplify add <category>" will allow you to add features like user login or a backend API
"amplify push" will build all your local backend resources and provision it in the cloud
"amplify console" to open the Amplify Console and view your project status
"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud


Pro tip:
Try "amplify add api" to create a backend API and then "amplify push" to deploy everything

ykethan@b0be8349b8b1 ~/D/a/g/analyticsupdate> amplify status

    Current Environment: dev
    
┌──────────┬─────────────────────────────────┬───────────┬───────────────────┐
│ Category │ Resource name                   │ Operation │ Provider plugin   │
├──────────┼─────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ analyticsupdate140386fb140386fb │ Delete    │ awscloudformation │
├──────────┼─────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ userPoolGroups                  │ Delete    │ awscloudformation │
└──────────┴─────────────────────────────────┴───────────┴───────────────────┘


ykethan@b0be8349b8b1 ~/D/a/g/analyticsupdate> amplify pull

Pre-pull status:

    Current Environment: dev
    
┌──────────┬─────────────────────────────────┬───────────┬───────────────────┐
│ Category │ Resource name                   │ Operation │ Provider plugin   │
├──────────┼─────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ analyticsupdate140386fb140386fb │ Delete    │ awscloudformation │
├──────────┼─────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ userPoolGroups                  │ Delete    │ awscloudformation │
└──────────┴─────────────────────────────────┴───────────┴───────────────────┘

⚠️ Local changes detected.
⚠️ Pulling changes from the cloud will override your local changes.
? Are you sure you would like to continue? Yes
✔ Successfully pulled backend environment dev from the cloud.
✅ 
Post-pull status:

    Current Environment: dev
    
┌──────────┬─────────────────────────────────┬───────────┬───────────────────┐
│ Category │ Resource name                   │ Operation │ Provider plugin   │
├──────────┼─────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ analyticsupdate140386fb140386fb │ No Change │ awscloudformation │
├──────────┼─────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ userPoolGroups                  │ No Change │ awscloudformation │
└──────────┴─────────────────────────────────┴───────────┴───────────────────┘
                                                                                                                                                                                                                     
ykethan@b0be8349b8b1 ~/D/a/g/analyticsupdate [SIGINT]> amplify env checkout prd
✔ Initialized provider successfully.
✅ Initialized your environment successfully.
ykethan@b0be8349b8b1 ~/D/a/g/analyticsupdate> amplify status

    Current Environment: prd
    
┌──────────┬─────────────────────────────────┬───────────┬───────────────────┐
│ Category │ Resource name                   │ Operation │ Provider plugin   │
├──────────┼─────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ analyticsupdate140386fb140386fb │ Create    │ awscloudformation │
├──────────┼─────────────────────────────────┼───────────┼───────────────────┤
│ Auth     │ userPoolGroups                  │ Create    │ awscloudformation │
└──────────┴─────────────────────────────────┴───────────┴───────────────────┘

ykethan avatar May 29 '24 16:05 ykethan

Closing the issue due to inactivity. Do reach out to us if you are still experiencing this issue

ykethan avatar Jul 03 '24 19:07 ykethan

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar Jul 03 '24 19:07 github-actions[bot]