Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to edit or update a table #295

Open
jcjp opened this issue Aug 24, 2022 · 2 comments
Open

How to edit or update a table #295

jcjp opened this issue Aug 24, 2022 · 2 comments

Comments

@jcjp
Copy link

jcjp commented Aug 24, 2022

Issue:

I want to update or edit a table to add a new index, instead of re-creating a new table with no data.

  • Is there a possibility to edit the created table?
  • Or maybe duplicate the current table with data but add new indices before creating?
  • Or this is an anti-pattern with the principle of DynamoDB?
@liesislukas
Copy link
Contributor

with live DynamoDB you can edit some things, especially GSIs and RCUs/WCUs. Yet local dynamodb is not live database, it seems to be based on sql and mimics DynamoDB APIs so you could develop/run tests without hitting real thing.

So no, it's not "anti-pattern" while apps do evolve and GSI/througoutput and some other settings may require changes over time even on live table.

I would love to see option to update or at least re-create from existing table new table. When you need to change some GSI and because of that now need to re-create full table is frustrating.

p.s. Why said seems like local dynamodb based on sql? Here are logs from from dynamo docker:

image

@uzair004
Copy link

uzair004 commented May 28, 2024

you can run following command to create GSI2 in your local db.
index name: GSI2
partition key name: PK2
range key name: SK2
table name: ...
region: your aws region

after running following command with updated details (name and keys names) you can look into Meta tab of your local db and should see a new GSI there.

aws dynamodb update-table \
  --region eu-central-1 \
  --endpoint-url http://127.0.0.1:8000/ \
  --table-name your-table-name-here \
  --attribute-definitions AttributeName=PK2,AttributeType=S AttributeName=SK2,AttributeType=S \
  --global-secondary-index-updates '[
    {
      "Create": {
        "IndexName": "GSI2",
        "KeySchema": [
          {
            "AttributeName": "PK2",
            "KeyType": "HASH"
          },
          {
            "AttributeName": "SK2",
            "KeyType": "RANGE"
          }
        ],
        "ProvisionedThroughput": {
          "ReadCapacityUnits": 10,
          "WriteCapacityUnits": 10
        },
        "Projection": {
          "ProjectionType": "ALL"
        }
      }
    }
  ]'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants