Renaming the Range Key of a DynamoDB table?

Hello all,

I’m working with a python script that’s defining a table using PynamoDB. Currently it has a single hash and range key, but the range key needs to be renamed. The data format will stay the same (timestamp), but the historical data needs to (ideally) use the new name.

I’m seeing conflicting sources when it comes to renaming the range key without having the migrate everything to a new instance. Anyone know the most up-to-date process for this? Thanks in advance!


Related discussions:

Pretty certain that the range key is immutable on the table on creation. Only Global Secondary Indexes can be changed after creation.

I couldn’t find any AWS documentation that spoke to this.

I did find this forum post, https://forums.aws.amazon.com/thread.jspa?threadID=91491:

> Each item in your dynamodb table should have the attribute you identified as the primary key

I did find this post which talks about how to migrate the database (I know you said you didn’t want to, though): https://www.abhayachauhan.com/2018/01/dynamodb-changing-table-schema/

this isn’t possible.

I’d highly recommend adapting your stack to be flexible with regard to the name of your DynamoDB tables. You cannot even use the built in backup and restore functionality and restore to an existing table name - you need to create a whole new table to restore.

Basically, DynamoDB is built around the concept of doing full copies from one table to another when you want to do a migration of any real consequence. Plan accordingly :stuck_out_tongue:

I’m working with a long-established system that I have no admin control over, ideally I’d start fresh but I got no choice here

oh, I can completely sympathize, don’t get me wrong.

I’m just letting you know, Dynamo literally doesn’t support renaming things without doing a full migration from one table to another.

the good news is, since ddb is schema-light, migrations are actually pretty simple - just do a table scan and copy everything over while renaming or transforming whatever you need to.

Dynamo literally doesn’t support renaming things without doing a full migration

You mean renaming index keys, right? To my knowledge, all other attributes can be added/removed/changed without causing any errors (aside from separate scripts not locating certain attributes).

yes, sorry, i didn’t mean to appear to conflate the two. I was assuming the context of the title, which talks about range keys.