1

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I read somewhere that key is mandatory for UpdateItem when we try it from aws cli command. But I don't have the key
If you don't have the key (hash/partition key and sort key if configured) then you would need to Scan your DynamoDB table to get the information (this is very cost inefficient). Is there no way to work out these values or is it an generated value?
For the example I have given, I have to update Grade for every row by considering their Salary, so irrespective of any (hash/partition key) I have to update it right?
Yes you would need to get all the data first (assuming its only in DynamoDB) and then update.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.