How can I update dynamodb GSI when projection type is changed?

Viewed 4202

I am using serverless framework to manage AWS infra and I have defined a dynamodb table with a GSI. Now I need to update the projection type of the GSi and I know that it is not allowed. So I manually delete the GSI from dynamodb table but I still get below error when running sls deploy:

An error occurred: DeviceTable - Cannot update GSI's properties other than Provisioned Throughput. You can create a new GSI with a different name..

What I don't understand is that the GSI has been removed but why it still complains about the GSI's properties. Is there any place remember the GIS? What is the right way to do that?

2 Answers

I had the same error. I work with the CDK but I think the problem is the same with the Serverless Framework. I solved it as follows:

  1. Delete the affected indexes from your configuration file (serverless.yaml or CDK files).
  2. Deploy the complete stack, not only one function
  3. Add the new or changed index again
  4. Deploy the complete stack, not only one function

This is how it worked for me.

ps: you can't replace the index with a new one, as mentioned above, you need to delete the old one and then add the new one. Or you will end up with an error message like this one: "Cannot perform more than one GSI creation or deletion in a single update"

I have faced the same issue. I tried to changed my ProjectionType but after that my serverless deployment started failing with the same error. As mentioned in the question, I also deleted my GSI from DynamoDb, but that did not help me as well. After Googling a lot, I did not get a proper answer. But this is how I resolved it finally.

  • When you get this error, you also get a link to the CloudFormation stack which you are trying to update with your GSI changes.
  • Follow this link and go to your CloudFormation stack, there click on Template tab.
  • After that click on View in Designer button or link whatever you call it.
  • It will load your stack in Designer template.
  • At the botton window, it will ask you to Choose template Language, chose YAML as the option.
  • Locate your DynamoDb table where you are trying to apply GSI. Here you will see the old previous GSI settings.
  • Now please remove only the GSI settings carefully without removing anything related to DynamoDb table settings.
  • Now from the top left, you will see a couple of options to Redo, Undo, and Create Stack etc. There you will also find a link Save.
  • Save the template as a Serverless file to your local computer.
  • Now go back to Template tab and this time click on the button Update.
  • Chose the option Replace current template and the Update a template file. Here upload the Serverless file which you saved earlier, and click on next to finally upload it.
  • Now wait for sometime to let the CloudFormation update the template for you.

That's it, now if you run your yarn sls command again, it won't stop you to let your new DynamoDb GSI projection settings get deployed.

One more tip, it takes some time to create a new GSI on Cloud, so please be patient and look for the Status Active on your DynamoDb table under the tab Indexes.

Related