Describe the bug
Currently have an app in development using Amplify and React Native.
While changing the schema to add some @keys and @connections, we started seeing the following error:
Attempting to add and remove a global secondary index at the same time on the TeamMatchTable table in the TeamMatch stack.
Cause: You may only change one global secondary index in a single CloudFormation stack update.
Since this is a development app, we tried creating a new environment in order to push there.
The same error happened with the new environment. It seems like it is somehow still pulling the schema from the old one.
$ amplify env checkout newdev
√ Initialized provider successfully.
√ Channel is not setup for APNS
√ Channel information retrieved for FCM
√ Channel is not setup for Email
√ Channel is not setup for SMS
Initialized your environment successfully.
$ amplify push
√ Successfully pulled backend environment newdev from the cloud.
Current Environment: newdev
| Category | Resource name | Operation | Provider plugin |
| ------------- | -------------------- | --------- | ----------------- |
| Auth | projectsportff7aed9e | Create | awscloudformation |
| Auth | userPoolGroups | Create | awscloudformation |
| Storage | s357851cbb | Create | awscloudformation |
| Analytics | projectsport | Create | awscloudformation |
| Api | projectsport | Create | awscloudformation |
| Api | AdminQueries | Create | awscloudformation |
| Function | AdminQueries51949811 | Create | awscloudformation |
| Notifications | projectsport | No Change | |
? Are you sure you want to continue? Yes
× An error occurred when pushing the resources to the cloud
Attempting to add and remove a global secondary index at the same time on the MemberTable table in the Member stack.
An error occured during the push operation: Attempting to add and remove a global secondary index at the same time on the MemberTable table in the Member stack.
Amplify CLI Version
$ amplify -v
4.18.0
Related to the actual problem: #2384 and #3903.
However, I think it should still allow pushing to a completely different environment.
As a troubleshooting step, we tried removing all models from schema.graphql and pushing an empty test model. The push finished properly.
When trying to push the full schema again, https://github.com/aws-amplify/amplify-cli/issues/682 happened.
The only working solution to get unblocked was to do what is described here: https://github.com/aws-amplify/amplify-cli/issues/682#issuecomment-598858263
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hi @andreialecu could you provide a snippet of your schema and where you tried to add @key and @connection?
Maybe the same issue as https://github.com/aws-amplify/amplify-cli/issues/3402
How I got to the fix: I faced the same issue when I created a new AWS account (of course you do amplify configure too). Since I would do amplify init and choose my env name + aws profile to use, amplify takes the #current-cloud-backend folder from your previous aws account deployed backend and puts it in to the new environment S3 deployment bucket (At least that's what I observed and I think that's what causes the issue)
The Fix: Before I did the amplify init, I deleted the folder #current-cloud-backend. Then amplify init created the folder again but alas, with only one file in it amplify-meta.json. This looked promising!!! The s3 deployment bucket was initialized as well during init. On amplify push the deployment to the new environment was successful without the errors.
Hope this solves your problem too :)
@andreialecu Were you able to get yourself unblocked based on @givenm's workaround? This looks like a bug but @givenm's workaround would save you deleting models and data in production.
I have also just encountered this issue when changing the schema but have not yet tried @givenm's workaround.
re I did the
amplify init, I deleted the folder#current-cloud-backend. Thenamplify initcreated the folder again but alas, with only one file in itamplify-meta.json. This looked promising!!! The s3 deployment bucket was initialized as well during init. Onamplify pushthe deployment to the new environment was successful without the errors.
This didn't work for me 😢
Any follow up from the team? Any guidance would be appreciated!
@loganpowell - not sure this is helpful but I encounter this with certain schema changes and do the following:
Obviously this is a problem if you are in production or need to preserve data - we are in development so can live with this.
Apparently this is a current limitation and the workaround is to create the new key and run 'amplify push' and then 'remove the unwanted or replaced key and then run 'amplify push'. So you can't just modify an existing definition - first create a new one and then in a separate push remove the one you wanted to replace/modify.
I also raised an issue and got a response from @yuth in this regard - they are working on a solution apparently.
https://github.com/aws-amplify/amplify-cli/issues/5558
Good luck
Any news on this? I had to restart a new environment every time while setting up our project because of this
It appears that keys are very restrictive when it comes to editing. The issue is this:
Cause: You may only change one global secondary index in a single CloudFormation stack update.
For instance, you can't modify the name of any existing key, as that would amount to deleting AND creating a new key in the same stack update. You must first delete the key, run amplify push, then add the key back.
The thing to keep in mind (would really like for this to be changed in the future) is that the keys are interpreted as a list, meaning they are ordered. If you have 3 keys on a given table, you can only ever delete the last key, as deleting any prior keys would result in these 'key indeces' being updated for every subsequent key, which would violate the above rule.
Most helpful comment
It appears that keys are very restrictive when it comes to editing. The issue is this:
Cause: You may only change one global secondary index in a single CloudFormation stack update.For instance, you can't modify the name of any existing key, as that would amount to deleting AND creating a new key in the same stack update. You must first delete the key, run
amplify push, then add the key back.The thing to keep in mind (would really like for this to be changed in the future) is that the keys are interpreted as a list, meaning they are ordered. If you have 3 keys on a given table, you can only ever delete the last key, as deleting any prior keys would result in these 'key indeces' being updated for every subsequent key, which would violate the above rule.