aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 79 forks source link

Amplify push failing when changing primary key #1797

Open ChadyG opened 1 year ago

ChadyG commented 1 year ago

How did you install the Amplify CLI?

homebrew

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

No response

Amplify CLI Version

12.2.4

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

Describe the bug

Previously pushed a test table with default key to our backend. Now pushing full schema with custom primary key on the new table. Using amplify push -y --allow-destructive-graphql-schema-updates But this is failing in an odd way. The push operation starts as expected, but once the status output should start, I'm seeing the console get cleared, then no output until the operations finish with errors.

Expected behavior

Amplify push succeed or fail as normal

Reproduction steps

  1. Update schema with new table
  2. Push to backend
  3. Update new table to use a custom primary key
  4. Push to backend using --allow-destructive-graphql-schema-updates

Project Identifier

No response

Log output

``` % amplify push -y --allow-destructive-graphql-schema-updates ⠇ Fetching updates to backend environment: prod from the cloud.⚠️ WARNING: owners may reassign ownership for the following model(s) and role(s): .... If this is not intentional, you may want to apply field-level authorization rules to these fields. To read more: https://docs.amplify.aws/cli/graphql/authorization-rules/#per-user--owner-based-data-access. ⠏ Fetching updates to backend environment: prod from the cloud.✅ GraphQL schema compiled successfully. Edit your schema at /Users/.../schema.graphql or place .graphql files in a directory at /Users/.../schema ✔ Successfully pulled backend environment prod from the cloud. ⠦ Building resource api/appName⚠️ WARNING: owners may reassign ownership for the following model(s) and role(s): .... If this is not intentional, you may want to apply field-level authorization rules to these fields. To read more: https://docs.amplify.aws/cli/graphql/authorization-rules/#per-user--owner-based-data-access. ⠧ Building resource api/appName✅ GraphQL schema compiled successfully. Edit your schema at /Users/.../schema.graphql or place .graphql files in a directory at /Users/.../schema Current Environment: prod ┌──────────┬─────────────────────────────────────────────────┬───────────┬───────────────────┐ │ Category │ Resource name │ Operation │ Provider plugin │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Auth │ userPoolGroups │ Create │ awscloudformation │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Function │ postConfirmationLambda │ Create │ awscloudformation │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Api │ apiBackend │ Update │ awscloudformation │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Auth │ authBackend │ Update │ awscloudformation │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Function │ statsSharedLambda │ Update │ awscloudformation │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Function │ removeUserAccountAndData │ Update │ awscloudformation │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Function │ shotsbycategory │ Update │ awscloudformation │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Function │ userExists │ Update │ awscloudformation │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Function │ clubaverages │ No Change │ awscloudformation │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Function │ fetchShadow │ No Change │ awscloudformation │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Function │ productRegistrationReport │ No Change │ awscloudformation │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Function │ sessionsinrange │ No Change │ awscloudformation │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Function │ sessionstats │ No Change │ awscloudformation │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Function │ shotsbyclub │ No Change │ awscloudformation │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Function │ shotsinrange │ No Change │ awscloudformation │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Function │ userstats │ No Change │ awscloudformation │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Function │ writeShadow │ No Change │ awscloudformation │ ├──────────┼─────────────────────────────────────────────────┼───────────┼───────────────────┤ │ Storage │ appStorage │ No Change │ awscloudformation │ └──────────┴─────────────────────────────────────────────────┴───────────┴───────────────────┘ ⚠️ WARNING: owners may reassign ownership for the following model(s) and role(s): .... If this is not intentional, you may want to apply field-level authorization rules to these fields. To read more: https://docs.amplify.aws/cli/graphql/authorization-rules/#per-user--owner-based-data-access. ✅ GraphQL schema compiled successfully. Edit your schema at /Users/.../schema.graphql or place .graphql files in a directory at /Users/.../schema Suggested configuration for new layer versions: statsSharedLambda - Access permissions: Maintain existing permissions - Description: Updated layer version 2023-08-10T13:39:55.315Z ⠧ Building resource api/appName⚠️ WARNING: owners may reassign ownership for the following model(s) and role(s): [...]. If this is not intentional, you may want to apply field-level authorization rules to these fields. To read more: https://docs.amplify.aws/cli/graphql/authorization-rules/#per-user--owner-based-data-access. ⠇ Building resource api/appName✅ GraphQL schema compiled successfully. Edit your schema at /Users/.../schema.graphql or place .graphql files in a directory at /Users/.../schema Deployment completed. Rolled back (2 of 1) 🛑 ["Index: 0 State: {\"deploy\":\"waitingForDeployment\"} Message: Resource is not in the state stackUpdateComplete"] Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/ ```

Additional information

Worked around by dropping the table entirely from the schema, pushing with destructive changes. Then re-adding the table and pushing as normal.

Before submitting, please confirm:

josefaidt commented 1 year ago

Hey @ChadyG :wave: thanks for raising this! I was able to reproduce this using the following steps:

  1. amplify init -y
  2. amplify add api > GraphQL > choose the "Todo" sample schema
  3. amplify push -y
  4. add @primaryKey to the name prop
    type Todo @model {
      id: ID!
      name: String! @primaryKey
      description: String
    }
  5. amplify push -y
  6. observe error
, review: https://docs.amplify.aws/cli/graphql/authorization-rules

⠋ Building resource api/13100✅ GraphQL schema compiled successfully.

Edit your schema at /Users/josefai/Documents/projects/aws-amplify/reproductions/13100/amplify/backend/api/13100/schema.graphql or place .graphql files in a directory at /Users/josefai/Documents/projects/aws-amplify/reproductions/13100/amplify/backend/api/13100/schema

Deployment completed.
Deploying api 13100 [ ====------------------------------------ ] 1/9
        GraphQLAPITransformerSchema3C… AWS::AppSync::GraphQLSchema    UPDATE_COMPLE

Rolled back (2 of 1)
🛑 ["Index: 0 State: {\"deploy\":\"waitingForDeployment\"} Message: Resource is not in the state stackUpdateComplete"]

Marking as a bug and transferring to our API repo for tracking purposes.

codenimble commented 9 months ago

I am also getting this error. I've been going around and around on this for days. Amplify is simply unusable.