question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamodb: add GSI to existing Dynamodb table via CDK deploy

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
mattiLeBlanccommented, Jan 7, 2021

Hi Adam, No man, that is it. Thanks again.

0reactions
github-actions[bot]commented, Jan 7, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

interface GlobalSecondaryIndexProps · AWS CDK
The values are placeholders you should change. import * as dynamodb from '@aws-cdk/aws-dynamodb'; const globalSecondaryIndexProps: dynamodb.
Read more >
Why does adding a secondary index to a dynamodb table ...
Why is that? Changes to LocalSecondaryIndexes require replacement of DynamoDB table, since LSI can only be created on the table create time.
Read more >
Add a Dynamodb Global Secondary Index in AWS CDK [GSI]
In order to add a Global Secondary Index to a Dynamodb Table in AWS CDK, we have to use the addGlobalSecondaryIndex method on...
Read more >
Step 6: Create a global secondary index
In the navigation pane on the left side of the console, choose Tables. · Choose the Music table from the table list. ·...
Read more >
DynamoDB With LocalStack And The AWS CDK (Part 1)
This post will use the AWS TypeScript CDK to deploy table to DynamoDB on LocalStack with single-table schema design. The code will build...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found