20 Days of DynamoDB
A DynamoDB tip a day, keeps the ...?
Day 20 - Converting between Go and DynamoDB types
Day 19 - PartiQL Batch Operations
Day 18 - Using a SQL-compatible query language with DynamoDB
Day 17 - DynamoDB BatchGetItem operation
Day 16 - Enhancing Write Performance with Batching
Day 15 - Using the DynamoDB expression package to build Update expressions
Day 14 - Using the DynamoDB expression package to build Key Condition and Filter expressions
Day 13 - Using the DynamoDB expression package to build Condition expressions
Day 12 - Using the DynamoDB expression package to build Projection expressions
Day 11 - Using pagination with Query API
Day 10 - Query API with Filter Expression
Day 8 - Conditional Delete operation
Day 6 - Atomic counters with UpdateItem
Day 5 - Avoid overwrites when using DynamoDB UpdateItem API
Day 4 - Conditional UpdateItem
attributevalue
package in the AWS SDK for Go package can save you a lot of time, thanks to the Marshal
and Unmarshal
family of utility functions that can be used to convert between Go types (including struct
s) and AttributeValue
s.struct
: MarshalMap
converts Customerstruct
into amap[string]types.AttributeValue
that's required byPutItem
UnmarshalMap
converts themap[string]types.AttributeValue
returned byGetItem
into a Customerstruct
- MarshalMap API doc
- UnmarshalMap API doc
- AttributeValue API doc
BatchExecuteStatement
. It allows you to batch reads as well as write requests.BatchWriteItem
, BatchExecuteStatement
is limited to 25 statements (operations) per batch.ExecuteStatement
API to execute INSERT
, SELECT
, UPDATE
and DELETE
:- Amazon DynamoDB documentation on PartiQL support
GetItem
requests in a single BatchGetItem
operation - this can be done across multiple tables.GetItem
calls across two different tables:GetItem
call, you can include Projection Expressions and return RCUs. Note that BatchGetItem
can only retrieve up to 16 MB of data.BatchWriteItem
operation can provide a performance boost by allowing you to squeeze in 25 individual PutItem
and DeleteItem
requests in a single API call - this can be done across multiple tables.PutItem
and DeleteItem
operations for two different tables (customer
, orders
):- The total request size cannot exceed 16 MB
BatchWriteItem
cannot update items
Update
expressions. SET
operation of the UpdateItem
API and combine it with a Condition
expression (update criteria):expression
package in the AWS Go SDK for DynamoDB to programmatically build key condition and filter expressions and use them with Query
API.expression
package in the AWS Go SDK for DynamoDB, you can programmatically build Condition expressions and use them with write operations. Here is an example with the DeleteItem
API:expression
package in the AWS Go SDK for DynamoDB provides a fluent builder API with types and functions to create expression strings programmatically along with corresponding expression attribute names and values.GetItem
API:Query
API returns the result set size to 1 MB
. Use ExclusiveStartKey
and LastEvaluatedKey
elements to paginate over large result sets. You can also reduce page size by limiting the number of items in the result set, with the Limit
parameter of the Query
operation.Query
API, you can use Filter Expressions to discard specific query results based on a criteria. Note that the filter expression is applied after a Query finishes, but before the results are returned. Thus, it has no impact on the RCUs (read capacity unit) consumed by the query.Query
API is used to model one-to-many relationships in DynamoDB. You can search for items based on (composite) primary key values using Key Condition Expressions. The value for partition key attribute is mandatory - the query returns all items with that partition key value. Additionally, you can also provide a sort key attribute and use a comparison operator to refine the search results.Message
attribute:Query
API, you can also:- Switch to strongly consistent read (eventual consistent being the default)
- Use a projection expression to return only some attributes
- Return the consumed Read Capacity Units (RCU)
DeleteItem
support criteria-based (conditional) execution. You can use DeleteItem
operation with a condition expression - it must evaluate to true
in order for the operation to succeed.inactive_days
attribute:- Return the content of the old item (at no additional cost)
- Return the consumed Write Capacity Units (WCU)
- Return the item attributes for an operation that failed a condition check (again, no additional cost)
- Retrieve statistics about item collections, if any, that were affected during the operation
- Use multiple update expressions in a single statement
- Get the item attributes as they appear before or after they are successfully updated
- Understand which item attributes failed the condition check (no additional cost)
- Retrieve the consumed Write Capacity Units (WCU)
- Switch to strongly consistent read (eventually consistent being the default)
- Use a projection expression to return only some of the attributes
- Return the consumed Read Capacity Units (RCU)
- Return the consumed Write Capacity Units (WCU)
- Get the item attributes as they appeared before (in case they were updated during the operation)
- Retrieve statistics about item collections, if any, that were modified during the operation
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.