-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Description
A way to use Table.addGlobalSecondaryIndex for existing tables so we can Add an inde to a existing table using the CDK.
Use Case
I create my DynamoDB tables via the CDK.
Now I have to add an index, so I want to ideally update the existing table and not recreate the table (no delete policy is enabled).
So, in my CDK script I check (using the SDK) if the table already exists. If it doesn't exist I use :
const table = new Table(this, tableName, options);
// and
table.addGlobalSecondaryIndex(options);
to create table and GSI.
However, if the table does already exist (in staging or prod), I am using
const table = Table.fromTableName(this, tableName, tableName);
to get a table reference ( so I can use that to get the datasource for Appsync resolvers and such).
The problem I have is that fromTableName returns an interface of ITable and not Table. ITable doesn't have the addGlobalSecondaryIndex function, only Table does.
So there is no way for me (as far as I know) to add an index to an existing table, either then removing the table first (bad) or adding it manually.
I have add a hacky workaround in my CDK deploy script using the SDK where I use the updateTable command from @aws-sdk/client-dynamodb however that is not ideal.
Proposed Solution
If the Table.fromTableName function would return a Table interface, that could allow us to call addGlobalSecondaryIndex or removeGlobalSecondaryIndex and update our tables via the CDK.
Other
- 👋 I may be able to implement this feature request
-
⚠️ This feature might incur a breaking change
This is a 🚀 Feature Request