aaronshaf/dynamodb-admin

How to edit or update a table

Opened this issue ยท 2 comments

jcjp commented

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?

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

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"
        }
      }
    }
  ]'