Reputation: 609
I'm new to dynamo DB and wanted to understand how a new attribute can be added to an existing table.
What is the best way to add a new attribute to an existing table in production and then update the items for that attribute based on some conditions? I'm thinking of doing this operation from a script
For example: I've a dynamo db table Employee and it currently has a column Salary in the production environment. The requirement is to add a new column called Grade and update it's values based on the Salary. How to achieve this in an efficient way with any external scripts?
I've tried it using aws dynamodb update-item
but the issue is I don't know the key for it.
Upvotes: 1
Views: 3948
Reputation: 35146
For the first part of your question, DynamoDB is schemaless (with a requirement for Hash and optionally the Sort Key if configured) so you will always be able to add an attribute just by performing a PutItem
or UpdateItem
with the extra attribute.
Depending on the size of the data and the maximum write capacity you will want to loop through and update the items in intervals (adding sleeps in between batches to prevent being throttled).
As the logic of grade
is determined by salary
but not directly the same value you will want to attempt this programmatically to classify in your script.
If you want to accelerate the time it takes for the task to write this new data you will need to increase the Write CPU for the duration of the script.
Upvotes: 1