amplify-cli: Delete or Create key fails: Attempting to mutate more than 1 global secondary index at the same time

Describe the bug

When attempting to delete a single key (no other changes) I get:

Attempting to mutate more than 1 global secondary index at the same time on the FooTable table in the Foo stack. 
An error occurred during the push operation: Attempting to mutate more than 1 global secondary index at the same time on the FooTable table in the Foo stack. 

Amplify CLI Version

4.29.2

To Reproduce

  1. Have a schema that has already been pushed with an example @key
  2. Try to delete the @key
  3. amplify push fails

Expected behavior

@key should be deleted

Additional context

Example schema:

type Foo
  @model
  @key(name: "FooStatusUpdatedAt", fields: ["status", "updatedAt"], queryField: "fooStatusUpdatedAt")
  @searchable
{
  updatedAt: AWSDateTime,
  status: PublicationStatus,
  ...
}

enum PublicationStatus {
  draft
}

Note: I downgraded to @aws-amplify/cli@4.27.3 and was able to perform the amplify push without issue.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 39 (10 by maintainers)

Most upvoted comments

Any updates on this?

I have the same problem, and I just found out that the order of the @key directives seems to matter. Going from this:

type Foo
  @model
  @key(name: "FooSubjectId", fields: ["fooSubjectId"], queryField: "fooSubjectId")

to this:

type Foo
  @model
  @key(name: "FooByUpdatedAt", fields: ["searchIndex", "updatedAt"], queryField: "fooByUpdatedAt")
  @key(name: "FooSubjectId", fields: ["fooSubjectId"], queryField: "fooSubjectId")

results in abovementioned error, but instead doing:

type Foo
  @model
  @key(name: "FooSubjectId", fields: ["fooSubjectId"], queryField: "fooSubjectId")
  @key(name: "FooByUpdatedAt", fields: ["searchIndex", "updatedAt"], queryField: "fooByUpdatedAt")

seems to work. My guess is that the diffing in the first case creates something like this:

DELETE FooSubjectId
CREATE FooByUpdatedAt
CREATE FooSubjectId

instead of this:

CREATE FooByUpdatedAt

@tsesamson Nope. I was able to remove the key by reverting to @aws-amplify/cli@4.27.3

I had the same issue. After downgrading it worked @andrewbtp .

I’m having the same issue using a custom CloudFormation resource containing a DynamoDB table. I’m only removing a previously created index from the file and Amplify doesn’t want to push.

I’m downgrading to @aws-amplify/cli@4.27.3 as a workaround, but that’s not ideal - especially when deploying in production from the console.

Yes that’s what I did. But if tomorrow I create a new branch, that is a duplicate of my actual branch, i will need to go through this procedure for every table that has 2 @key or more. That’s not normal. What will I say to my employee that needs to duplicate the master? And what if i have 3000 tables with multiple @keys? Your solution has no cense. It works only for small school project, not for pro ones

And if i want to switch from prode to mock, it means i have to push the @key one by one as well? It has noooo cense image

Please consider this as being a bug

You have to work with the limitations of the tools you use and determine if all the other stuff it does for you is worth it.

We release our changes with one key change at a time. Or we work on separate branches and merge changes in sequence.

Any updates? This is blocking production fix that is really needed.

@mikeparisstuff - any insight into this?

I used the @maximelebastard downgrade solution and it worked, and once pushed, I had to reinstall the latest version of the cli and continue

I have this problem right now. on 4.32.1.

I’m trying to add the first key on a model. It keeps saying the same error.