Boto3 updating multiple values
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
When people ask about updating multiple values with Boto3, they are often working with DynamoDB and want to change several attributes in one request. The usual solution is update_item with a single UpdateExpression that sets every target attribute together.
Update Multiple Attributes In One update_item Call
In DynamoDB, a single update_item call can modify more than one field on the same item. The normal pattern is to build one SET expression with several assignments.
This updates price, stock, and status in one request. ReturnValues="ALL_NEW" asks DynamoDB to return the updated item attributes so you can confirm the result immediately.
Use Expression Attribute Names For Reserved Words
Sometimes an attribute name conflicts with a DynamoDB reserved word, or it contains characters that are awkward inside an expression. In those cases, alias the attribute names.
This makes the update expression easier to maintain and prevents odd failures caused by reserved keywords.
Combine SET, REMOVE, And Arithmetic Updates
update_item is not limited to plain replacements. You can combine different update operations in one statement.
This increments login_count, replaces last_login, and removes temporary_code in a single request for the same item. That is often cleaner and safer than issuing several separate updates back to back.
Add Conditions When The Update Must Be Safe
Many real updates should happen only if the item is already in a specific state. DynamoDB supports this with ConditionExpression.
This is important when several workers or requests might try to update the same item concurrently.
Know What "Multiple Values" Does And Does Not Mean
A single update_item call can update many attributes on one item. It does not mean you are updating many different items at once. If you need to touch several items atomically, you are in transaction territory instead of ordinary update_item territory.
That distinction matters because developers sometimes expect one update expression to act like a batch update across many partition keys. DynamoDB does not work that way.
Common Pitfalls
- Updating multiple attributes on one item but forgetting that DynamoDB numbers should often use
Decimalin Python. - Writing attribute names directly in the expression when a reserved word requires an alias.
- Assuming one
update_itemcall can update several different items. - Splitting logically related changes into many requests when one update expression would be clearer.
- Forgetting
ConditionExpressionwhen correctness depends on the item's existing state.
Summary
- Use one
update_itemcall with a multi-partUpdateExpressionto change several attributes on one DynamoDB item. - Alias attribute names with
ExpressionAttributeNameswhen necessary. - Combine
SET, arithmetic changes, andREMOVEoperations when that matches the update logic. - Add
ConditionExpressionwhen correctness depends on the item's existing state.
Related reading
- Boto3/S3 Renaming an object using copy_object
- Boto - Uploading file to a specific location on Amazon S3
- Boto 3 DynamoDB batchWriteItem Invalid attribute value type when specifying types
- botocore.exceptions.ClientError An error occurred 404 when calling the HeadObject operation Not Found
- Broken references in Virtualenvs
- bs4.FeatureNotFound Couldn't find a tree builder with the features you requested lxml. Do you need to install a parser library?
- Budget Capping in horizontal scaling
- Build a multi node Kafka cluster on docker swarm

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.