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

Upgrade from v4 to v10 fails on amplify push --force

Open apanagos opened this issue 4 years ago โ€ข 35 comments

Before opening, please confirm:

  • [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • [X] I have searched for duplicate or closed issues.
  • [X] I have read the guide for submitting bug reports.
  • [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.

How did you install the Amplify CLI?

npm install -g @aws-amplify/cli

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

v16.17.0

Amplify CLI Version

10.5.1

What operating system are you using?

Ubuntu

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

No

Amplify Categories

auth, storage, function, api, analytics, hosting, notifications

Amplify Commands

push

Describe the bug

I have an application in production, built and deployed 2 years ago with Amplify v4.21.1. I would like to upgrade it to the latest v10.5.1. I have followed some guide lines in upgrading but when I push it is failing. The CloudFormation stack events shows it is creating most of the functions but it fails on LogicID: APIGatewayAuthStack with Reason: Output 'ApiId' not found in stack 'arn:aws:cloudformation:us-east-1:*********:stack/amplify-trueedge-upgradedev-152256-apitrueEdgeTipSender-1TGQ1K4KPUIZ2/fa7ef070-6d14-11ed-ba09-0e838d9aecf1

Expected behavior

I expect it to deploy.

Reproduction steps

git check out the src for dev

create an environment to test changes

amplify env add

successful

push and migrate

amplify push --force

? Do you want to update code for your updated GraphQL API Yes ? Do you want to generate GraphQL statements (queries, mutations and subscription) based on your schema types? This will overwrite your current graphql queries, mutations and subscriptions Yes

Proceeds to create resources. I follow it on the cloudformation stack in console. Fails when it gets to APIGatewayAuthStack. image

GraphQL schema(s)

# Put schemas below this line


Project Identifier

Project Identifier: 6b057d3ed44286bcae9e76962f89929a

Log output


2022-11-25T23:08:24.991Z|error : Resource is not in the state stackUpdateComplete
DeploymentFault: Resource is not in the state stackUpdateComplete


Additional information

I see some files have been changed: settings.json was added team-provider-info.json was modified with the new env added. cli-inputs.json added The cloudformation templates for the lambda functions were updated with the latest runtime: nodejs16.x

apanagos avatar Nov 26 '22 22:11 apanagos

Hey @apanagos :wave: thanks for raising this! Amplify CLI v4 was released quite a while ago and there have been many changes that could be a factor here. Part of these changes was the introduction of amplify migrate <category>, namely api. Can you try to migrate this resource with amplify migrate api?

josefaidt avatar Nov 28 '22 16:11 josefaidt

Thanks @josefaidt I had tried previously but it failed. I tried again to capture the error seen below.

amplify migrate api
A migration is needed to support latest updates on api resources.

Recommended to try in a non-production environment first. Run "amplify env add" to create or clone an environment.
Custom CloudFormation changes will NOT be preserved. Custom changes can be made with "amplify api override" after migration.

Learn more about this migration: https://docs.amplify.aws/cli/migration/override
Do you want to migrate api resource "trueEdgeData"? (Y/n) ยท yes

There was an error migrating your project.
auth configuration not present for trueEdgeData. Try amplify pull to sync your folder structure

I thought maybe it was an issue with the auth category, so I tried that (amplify migrate auth) but it started asking me questions as if it is setting it up again for the first time and then asked if I wanted to delete the existing user pool which I didn't.

Maybe I did something wrong there?

apanagos avatar Nov 28 '22 20:11 apanagos

Hey @apanagos that does sound odd. Can you paste the output of the execution for migrate auth?

josefaidt avatar Nov 29 '22 00:11 josefaidt

Hi @josefaidt , I looked at my history and it was amplify update auth NOT migrate auth. Do you still want me to run update auth?

Just for FYI, I ran amplify status to see the output:

amplify status

Current Environment: upgradedev
Category Resource name Operation Provider plugin
Auth trueedge97d2517a Create awscloudformation
Api trueEdgeData Create awscloudformation
Api userManagerLambda Create awscloudformation
Api trueEdgeTipSender Create awscloudformation
Api tmpdatamover Create awscloudformation
Api tedgeChargeLambda Create awscloudformation
Api tipReceive Create awscloudformation
Api forgotUsername Create awscloudformation
Api helpRespond Create awscloudformation
Function userManagerLambda Create awscloudformation
Function trueEdgeTipSender Create awscloudformation
Function tmpdatamover Create awscloudformation
Function tedgeChargeLambda Create awscloudformation
Function tipReceive Create awscloudformation
Function loginChecker Create awscloudformation
Function streamCounter Create awscloudformation
Function tipStreamCounter Create awscloudformation
Function ebtStreamCounter Create awscloudformation
Function eddieStreamCounter Create awscloudformation
Function companyStreamCounter Create awscloudformation
Function forgotUsername Create awscloudformation
Function helpRespond Create awscloudformation
Function onDemandCounter Create awscloudformation
Storage edges3resource Create awscloudformation

GraphQL transformer version: 1


apanagos avatar Nov 29 '22 02:11 apanagos

Hey @apanagos thanks for clarifying, can you paste the output of your cli.json file? Perhaps there is a mismatch in feature flag configuration that is blocking the migration. Is access to the trueEdgeData api restricted?

josefaidt avatar Nov 30 '22 20:11 josefaidt

Here is cli.json

{
  "features": {
    "graphqltransformer": {
      "addmissingownerfields": false,
      "improvepluralization": false,
      "validatetypenamereservedwords": true,
      "useexperimentalpipelinedtransformer": false,
      "enableiterativegsiupdates": false,
      "secondarykeyasgsi": false,
      "skipoverridemutationinputtypes": false,
      "transformerversion": 1,
      "suppressschemamigrationprompt": true,
      "securityenhancementnotification": true,
      "showfieldauthnotification": true,
      "usesubusernamefordefaultidentityclaim": true,
      "usefieldnameforprimarykeyconnectionfield": false,
      "enableautoindexquerynames": false,
      "respectprimarykeyattributesonconnectionfield": false,
      "shoulddeepmergedirectiveconfigdefaults": false,
      "populateownerfieldforstaticgroupauth": false,
      "securityEnhancementNotification": false,
      "showFieldAuthNotification": false
    },
    "frontend-ios": {
      "enablexcodeintegration": false
    },
    "auth": {
      "enablecaseinsensitivity": false,
      "useinclusiveterminology": false,
      "breakcirculardependency": false,
      "forcealiasattributes": false,
      "useenabledmfas": false
    },
    "codegen": {
      "useappsyncmodelgenplugin": false,
      "usedocsgeneratorplugin": false,
      "usetypesgeneratorplugin": false,
      "cleangeneratedmodelsdirectory": false,
      "retaincasestyle": false,
      "addtimestampfields": false,
      "handlelistnullabilitytransparently": false,
      "emitauthprovider": false,
      "generateindexrules": false,
      "enabledartnullsafety": false
    },
    "appsync": {
      "generategraphqlpermissions": false
    },
    "latestregionsupport": {
      "pinpoint": 0,
      "translate": 0,
      "transcribe": 0,
      "rekognition": 0,
      "textract": 0,
      "comprehend": 0
    },
    "project": {
      "overrides": true
    }
  },
  "debug": {
    "shareProjectConfig": true
  }
}

apanagos avatar Nov 30 '22 21:11 apanagos

And trueEdgeData is restricted to user pool access. Is that what you are asking?

parameters.json

{
  "AppSyncApiName": "trueEdgeData",
  "DynamoDBBillingMode": "PAY_PER_REQUEST",
  "AuthCognitoUserPoolId": {
    "Fn::GetAtt": [
      "authtrueedge97d2517a",
      "Outputs.UserPoolId"
    ]
  }
}

apanagos avatar Nov 30 '22 21:11 apanagos

Hi @josefaidt , have you had a chance to review my feedback? Thanks again so much for your assistance. If this is going to be an up hill battle what are other options I can look at? If I have to redo this with the latest Amplify CLI, then I am going to have to migrate production data for users (cognito), and dynamodb.

apanagos avatar Dec 05 '22 15:12 apanagos

Hey @apanagos apologies for the delay, and thank you for posting those details! As a potential workaround, are you able to run amplify update api, bypass the migration prompt, and unset the auth configuration? From here, can you re-attempt running amplify migrate api, then reinstantiate the auth restrictions? This file appears to be created for the first time on push, though unfortunately it appears to reference an API ID that does not exist yet.

In amplify/backend/awscloudformation/build/awscloudformation/build/root-cloudformation-stack.json we can see which API ID this is attempting to reference

"APIGatewayAuthStack": {
  "Type": "AWS::CloudFormation::Stack",
  "Properties": {
    "TemplateURL": "https://s3.amazonaws.com/amplify-funwithlayers-dev-124037-deployment/amplify-cfn-templates/api/APIGatewayAuthStack.json",
    "Parameters": {
      "authRoleName": {
        "Ref": "AuthRoleName"
      },
      "unauthRoleName": {
        "Ref": "UnauthRoleName"
      },
      "env": "dev",
      "api53693695": {
        "Fn::GetAtt": [
          "apiapi53693695",
          "Outputs.ApiId"
        ]
      }
    }
  }
},

josefaidt avatar Dec 06 '22 20:12 josefaidt

Additionally in amplify/backend/awscloudformation/build/api/<api-name>/build/<api-name>-cloudformation-template.json we should see an Outputs block with ApiId. Do you see this output in apitrueEdgeTipSender's CloudFormation template?

"Outputs": {
    "RootUrl": {
      "Description": "Root URL of the API gateway",
      "Value": {
        "Fn::Join": [
          "",
          [
            "https://",
            {
              "Ref": "api53693695"
            },
            ".execute-api.",
            {
              "Ref": "AWS::Region"
            },
            ".amazonaws.com/",
            {
              "Fn::If": [
                "ShouldNotCreateEnvResources",
                "Prod",
                {
                  "Ref": "env"
                }
              ]
            }
          ]
        ]
      }
    },
    "ApiName": {
      "Description": "API Friendly name",
      "Value": "api53693695"
    },
    "ApiId": {
      "Description": "API ID (prefix of API URL)",
      "Value": {
        "Ref": "api53693695"
      }
    }

josefaidt avatar Dec 06 '22 20:12 josefaidt

@josefaidt , thank you so much. I really appreciate your feedback. I am out sick for a couple of days but will circle back and try out your suggestions hopefully tomorrow.

apanagos avatar Dec 07 '22 15:12 apanagos

No worries @apanagos I hope you feel better! We will keep this issue open ๐Ÿ™‚

josefaidt avatar Dec 07 '22 17:12 josefaidt

Hi @josefaidt , sorry about the delay but I was having surgery and recovering. Anyway I tried some of your recommendations from above but had issues.

When I ran amplify update api it errored out. image

That is with a "no" for "Do you want to migrate api resource "trueEdgeData"? For root-cloudformation-stack.json I could not find that anywhere.

Then the following is my Outputs in the cloudformation template for trueEdgeData.

  "Outputs": {
    "RootUrl": {
      "Description": "Root URL of the API gateway",
      "Value": {
        "Fn::Join": [
          "",
          [
            "https://",
            {
              "Ref": "trueEdgeTipSender"
            },
            ".execute-api.",
            {
              "Ref": "AWS::Region"
            },
            ".amazonaws.com/",
            {
              "Fn::If": [
                "ShouldNotCreateEnvResources",
                "Prod",
                {
                  "Ref": "env"
                }
              ]
            }
          ]
        ]
      }
    },
    "ApiName": {
      "Description": "API Friendly name",
      "Value": "trueEdgeTipSender"
    }
  }

apanagos avatar Dec 12 '22 22:12 apanagos

Hey @apanagos no worries! ๐Ÿ™‚ And that is an interesting error. Would you mind sending us a zip archive of your amplify/ directory to [email protected]?

josefaidt avatar Dec 15 '22 22:12 josefaidt

sure. will do.

apanagos avatar Dec 16 '22 18:12 apanagos

Thanks @josefaidt , I emailed it.

apanagos avatar Dec 16 '22 18:12 apanagos

Hey @apanagos it appears the zip archive was stripped from the email. Would you mind adding it to a file sharing service and emailing the link?

josefaidt avatar Dec 19 '22 23:12 josefaidt

Sent it with a link to download

apanagos avatar Dec 20 '22 01:12 apanagos

Hey @apanagos thanks for sending that over!! I was able to amplify init off your project into my own environment and find the issue, and a potential workaround. Previously I mistook this API for a REST API, however upon further inspection this is related to GraphQL API migration. To mitigate the "no auth config..." issue for your GraphQL API, in amplify/backend-config.json can you attempt manually changing the following?

"trueEdgeData": {
      "service": "AppSync",
      "providerPlugin": "awscloudformation",
      "output": {
        "securityType": "AMAZON_COGNITO_USER_POOLS"
      }
    },

to:

"trueEdgeData": {
      "service": "AppSync",
      "providerPlugin": "awscloudformation",
      "output": {
        "authConfig": {
          "defaultAuthentication": {
            "authenticationType": "AMAZON_COGNITO_USER_POOLS",
            "userPoolConfig": {
              "userPoolId": "trueedge97d2517a"
            }
          },
          "additionalAuthenticationProviders": []
        }
      }
    },

From here I was able to successfully migrate the resource with amplify migrate api

josefaidt avatar Dec 21 '22 19:12 josefaidt

Excellent!! Will try it out.

apanagos avatar Dec 21 '22 19:12 apanagos