Dynamo Basic APIs
Some of the APIS for DynamoDB
PutItem
: create or replace an item. Consumes WCUsUpdateItem
: edit an item's attributesConditional Writes
:- accept write, update, delete only condition is met, else returns error
- Good for concurrency
- No performance impact
- See: DynamoDB Optimistic Locking
GetItem
- Read based on Primary Key
- Eventually Consistent (default)
- Strongly Consistent might take longer and consumes more RCU
ProjectionExpression
can be specified to receive only certain attributes
Query
- To query item, using
KeyConditionExpress
:- partion key value (required)
- must use
=
operator. See DynamoDB Hash Primary Key
- must use
- Sort key value (optional), can use
=, < , >, >=, ...
See DynamoDB Hash and Range Primary key
- partion key value (required)
FilterExpression
- Additional filtering after
query
is executed (before data is return to you) - use only with non-key attribute (no HASH or RANGE key)
- happening in client-side
- Additional filtering after
- Return the number of items specified in
Limit
or up to 1 MB of data - Ability to do pagination
- Can query table, local secondary index or global secondary index
- To query item, using
Scan
:- read entire table and then filter out data (inefficient)
- Returns up to 1 MB of data - use pagination to read more
- Use
Limit
to reduce size of result and pause
- Use
- Consumes a lot of RCU
- For faster performance, can use
Parallel Scan
- Can use
ProjectionExpression
&FilterExpression
(no changes to RCU)
DeleteItem
- Delete an individual item
- Ability to perform a conditional delete
DeleteTable
- Delete whole table and all its items
- Ntoe: Much quicker deletion than calling
DeleteItem
on all items
Batch Operations
Save latency by reducing number of APIs. Operations are done in parallel for better efficiency
Part of batch can fail, we can try again for the failed items
BatchWriteItem
- up to 25
PutItem
and/orDeleteItem
in one call - Up to 16 MB of data written, 400 KB of data per item
- can't update items (you need to use
UpdateItem
)
- up to 25
BatchGetItem
- Return items from one or more tables
- Up to 100 items, up to 16 MB of data
- items are retrieved in parallel to minimize latency