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 78 forks source link

Resource handler returned message: "Cannot perform more than one GSI creation or deletion in a single update" #1584

Open nxia416 opened 1 year ago

nxia416 commented 1 year ago

How did you install the Amplify CLI?

yarn

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

v16.14.2

Amplify CLI Version

12.1.1

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.

Tried delete GSIs and added back

Describe the bug

image

🛑 The following resources failed to deploy: Resource Name: CouponTable (AWS::DynamoDB::Table) Event Type: update Reason: Resource handler returned message: "Cannot perform more than one GSI creation or deletion in a single update" (RequestToken: a993b865-7a0d-8dda-5771-47cde13bc1d0, HandlerErrorCode: InvalidRequest) URL: https://console.aws.amazon.com/cloudformation/home?region=xxxxxx#/stacks/arn%3Aaws%3Acloudformation%3Aap-southeast-1%3Axxxxxxxx%3Astack%2Famplify-xxxx-apixxx-XXXX-Coupon-FE39UJC7WKM7%2F10ee48e0-xxxx-xxxx-xxxx-0a6dc331856c/events

🛑 Resource is not in the state stackUpdateComplete Name: CouponTable (AWS::DynamoDB::Table), Event Type: update, Reason: Resource handler returned message: "Cannot perform more than one GSI creation or deletion in a single update" (RequestToken: a993b865-7a0d-8dda-5771-47cde13bc1d0, HandlerErrorCode: InvalidRequest), IsCustomResource: false

Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/

Expected behavior

I expect the api could rollback or update. However after amplify pull, I can't do anything to update amplify backend

Reproduction steps

I think I added 2 GSIs and removed 1 in the same git commit, and accidentally pushed it to amplify backend. After that, I can't change anything for the graphql API: always get the error message as shown in the picture.

Project Identifier

amplify diagnose --send-report

Learn more at https://docs.amplify.aws/cli/reference/diagnose/

✅ Report saved: /var/folders/2j/4v3x_j4x7x509ghkl7dwcps80000gp/T/cvmapi/report-1687166941401.zip

✔ Done

Project Identifier: 91cdde8f9febd928b9321cf78bea1dc1

Log output

``` # Put your logs below this line ```

Additional information

I have this coupon table and try to update it, the old schema is:

type Coupon
  @model
  @auth(
    rules: [
      { allow: public, operations: [read], provider: iam }
      { allow: private, operations: [read] }
      {
        allow: owner
        operations: [create, read, update, delete]
        ownerField: "userId"
      }
      {
        allow: groups
        groups: ["Admin"]
        operations: [create, read, update, delete]
      }
    ]
  ) {
  id: ID!
  service: Service! @belongsTo(fields: ["serviceId"])
  serviceId: ID!
    @index(
      name: "byServiceId"
      sortKeyFields: ["updatedAt"]
      queryField: "getCouponsByServiceId"
    )
  code: String!
  data: String
  ...
  userId: ID! @index(name: "byUserId", queryField: "getCouponsByUserId")
}

The new schema is:

type Coupon
  @model
  @auth(
    rules: [
      { allow: public, operations: [read], provider: iam }
      { allow: private, operations: [read] }
      {
        allow: owner
        operations: [create, read, update, delete]
        ownerField: "providerId"
      }
      {
        allow: groups
        groups: ["Admin"]
        operations: [create, read, update, delete]
      }
    ]
  ) {
  id: ID!
  service: Service @belongsTo(fields: ["serviceId"])
  serviceId: ID
    @index(
      name: "byServiceId"
      sortKeyFields: ["updatedAt"]
      queryField: "getCouponsByServiceId"
    )
  exclusive: Boolean
  code: String!
  data: String
  ...
  providerId: ID
    @index(name: "byProviderId", queryField: "getCouponsByProviderId")
  receiverId: ID
    @index(name: "byReceiverId", queryField: "getCouponsByReceiverId")
}

So, there are several changes to the GSI, I didn't notice and pushed to Amplify. Now the API is stuck.

I tried several methods:

1, amplify push --force, not working... 2, amplify pull --appId xxxxxx --envName prod and push again, still get the same error message. Another strange thing is, the pulled schema.graphql is not sync with AppSync. 3, There are other functions accessing the Coupon table, so I couldn't remove the table...

Now I know I have to update the GSI one by one. But the question now is how to make amplify push work again...

Before submitting, please confirm:

ykethan commented 1 year ago

hey @nxia416,👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂.

phani-srikar commented 1 year ago

Hi @nxia416, can you try the steps noted in this comment and see if you're able to re-deploy?

nxia416 commented 1 year ago

Thanks @ykethan , I tried the method and still get the same result. I think my problem is similar to #1425, however I am on Product env.

I think this could be a serious problem: I updated the API step by step in dev, but accidentally pushed all changes together to production. And now, it is stuck there.

Any suggestion?

nxia416 commented 1 year ago

More information:

image

amplify pull --appId xxxxxx --envName prod get an older version schema. But AppSync suggests the changes are already made. It seems the amplify and appsync are inconsistent.

shopizer-ecommerce commented 1 year ago

I am having the same issue with amplify cli 12.4.0 How did you got out of this situaton, we are stucked