3

I have a DynamoDB table called Transactions in which I am recording an audit trail of activity in my app. After midnight I would like to rename the table to something like Transactions.2015-10-01 and create a new table called Transactions, to which I would record the next 24 hours of activity in my app. At the end of that period I would rename that to Transactions.2015-10-02 etc.

In other words, I'm trying to implement a rotating log of activity (though linear rather than circular).

I'm not sure there's a way to rename a table in DynamoDB. Is there a way? If not, is there another approach? For example, if there was a table pointer that was called Transactions that would point to Transactions.2015-10-01 and then at midnight that pointer would switch to to Transactions.2015-10-02. My app audit logic would simply perform insertions into Transactions which delegates to the right table.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106
  • Possible duplicate of [How to rename a DynamoDB table](https://stackoverflow.com/questions/21410851/how-to-rename-a-dynamodb-table) – Bryan Sep 20 '18 at 08:46
  • Just for the record: To me it feels weird to have one table for every day. DynamoDB tables are capable of scaling really big. You might want to use the adjacency list pattern instead, inside a single table. – Simon Forsberg Mar 07 '20 at 15:19

2 Answers2

7

Amazon DynamoDB does not have a command to rename tables. The only table-related commands are CreateTable, DeleteTable, DescribeTable, ListTables and UpdateTable (which does not permit a rename).

Nor is there the ability to create aliases to tables.

The best approach would be for your application to create the desired tables and then direct transactions to the appropriate table.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • Sadly I reencountered this situation this week.Thankfully it was sufficient to make property file changes. Lesson: don’t hardcore your table names, use System.getProperty() – Sridhar Sarnobat Feb 02 '19 at 06:52
4

Not exactly a work around, but you can create a backup, restore the backup to a new table with a new name, then optionally remove the original table.

This is not a "rename", and it could break a lot of things. Just a hint. Don't go ahead and do it on your production server!

Bing Ren
  • 1,589
  • 17
  • 26