DynamoDB (ACG) Flashcards
What is DynamoDB?
DynamoDB is a low latency NoSQL database
What data models does DynamoDB support?
Supports both document and key-value data models. Supported document formats are JSON, HTML, and XML.
What are the different consistency models in DynamoDB?
- Eventually consistent
- Strongly consistent
- DynamoDB transactions
Name three DynamoDB features
DynamoDB consists of:
- tables
- items
- attributes
What are the 2 types of primary keys in DynamoDB?
- Partition Key
2. Composite Key (partition key + sort key)
What is a HASH key?
The partition/primary key was formerly known as a hash key.
How do you control access to DynamoDB?
IAM (Identity Access Management).
You can create IAM users within your AWS account with specific permissions to access and create DynamoDB tables.
You can also create IAM roles, enabling temporary access.
How do you restrict user access to DynamoDB?
You can use a special IAM condition parameter “dynamodb:LeadingKeys to restrict user access to only the items where the partition key matches their User_ID.
What is a secondary index?
An secondary index allows you to perform more flexible querying within DynamoDB.
Queries can be run on non-primary key attributes using global secondary indexes and local secondary indexes.
A secondary index allows you to perform fast queries on specific columns in a table, rather than on the entire dataset.
A local secondary index can only be created when you are creating your table. True or False?
TRUE
It also has the same partition key as your primary table, but a different sort key.
A global secondary index can only be created when you create your table. True or False?
FALSE
A global secondary index can be created at any time.
Uses a different primary key and different sort key to your table.
Should you use a Query or Scan?
Avoid scans!
Queries are much more efficient than a scan. A scan dumps the entire table and filters out the values. Scans can easily eat up all your provisioned throughput as the table grows.
A query finds items in a table using only the primary key attribute. You provide the primary key name and a distinct value to search for. True or False?
TRUE
Query results are always sorted by the sort key in ascending order if there is one.
TRUE
For queries and scans, what parameter is used to refine results?
ProjectionExpression parameter
What parameter can you use to reverse the sort order?
Set ScanIndexForward parameter to false to reverse the order of query results.
How can you reduce the impact of a query or scan?
- Setting a smaller page size which uses fewer read operations
- For scans, isolate scan operations to specific tables and segregate them from your mission-critical traffic
- Alternatively, try parallel scans rather than the default sequential scans
- A query operation is generally more efficient than a scan
- Avoid scans and design tables in a way that you can use the Query, Get or BatchGetItem APIs.
Name commonly used DynamoDB CLI commands
Be aware that the user must have the correct IAM permissions to run these commands. CLI commands are making calls to a DynamoDB API, e.g. CreateTable, PutItem, etc.
create-table put-item get-item update-item update-table list-tables describe-table scan query delete-item delete-table
What is DynamoDB provisioned throughput measured in?
Capacity units:
1 write capacity unit = 1KB write per second
1 read capacity unit =
1 x strongly consistent read of 4KB per second
OR
2 x eventually consistent read of 4KB per second
Your app needs to read 80 items per second. Each item is 3KB in size. You need strongly consistent reads. How many read capacity units will you need?
1 read capacity unit = 4KB strongly consistent read per second
3KB / 4KB = 0.75 = round-up to whole number 1
1 x 80 reads items per seconds = 80 read capacity units
For eventually consistent reads:
1 read capacity unit = 2 x 4KB eventually consistent reads per second
3KB / 4KB = 0.75 = round-up to whole number 1
80 read items per second / 2 = 40 read capacity units