Control plane

The control plane provides interaction with high-level operations to manage objects as tables and indexes.

In this example, we will create a new table to hold musical artists information that will be queried by artist.

The AWS CLI could also be used to control the tables management.

  • Create table:
aws dynamodb create-table --table-name Music --attribute-definitions AttributeName=Artist,AttributeType=S --key-schema AttributeName=Artist,KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
  • List tables:
aws dynamodb list-tables
  • Describe table:
aws dynamodb describe-table --table-name Music

  • Update table: 

The update table action is used to add indexes, modify the table throughput and enable trigger style events called DynamoDB Streams.

Let's increase 100% of the table capacity.

aws dynamodb update-table --table-name Music --provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=10
  • Delete table:
aws dynamodb delete-table --table-name Music
  • Data plane: 

One of the most important topics about table design is the key architecture. Think about DynamoDB as a series of servers storing and retrieving data from multiple partitions to increase throughput. Design your tables with a key attribute with the highest cardinality, to promote uniform data distribution across all partitions.

  • Simple Primary Key: 

The minimum attributes to define a table in DynamoDB is to provide a partition key, this attribute is known as the hash attribute. In order to perform queries, you need to provide the table name and the primary key value to be able to get one particular item.

Once you have created the Artist table, choose Create item. This will show a popup window where you can introduce the item attributes, in our example, we are choosing the simplest model specifying only the partition key. Add one item with your favorite artist name; add a second one but this time use more attributes like in the following example:

The artist name is a good partition key because every artist name is different and there are many different artists. A bad partition key would be to use the genre where there are few music categories (low ordinality).

Non relational databases are designed to be schemaless which results in huge gains for models that change frequently promoting flexibility in the future. Maybe applications will evolve and a new set of attributes will need to be persisted. There is no need to alter the physical structure of the tables, you simply put items with the required attributes. Application data access objects (DAOs) need to be aware of this evolution and be able to query different types of entities.

    • Scan: The Scan operation will read sequentially all the items in the table up to 1 MB of data. This is the less efficient and costliest operation in DynamoDB. It is a good idea to use it to retrieve catalog data and then cache it somewhere.
    • Query: Our Music table can be queried in the following way:

In order to perform a query to the Music table, I need to make use of the Artist index, there is no other strategy to query this table. What happens when we have composite keys? Now we have another strategy we can use the Artist name and the Song name; this unique combination will retrieve the specific item in the table. Delete the table and create a new one with the following table specification for the primary key.

  • Composite Primary Key

A sorting key let queries to be performed on a subgroup of data that share the same primary key with a unique component which is the range (sort key). This is a 1:M relationship, for example, multiple cities in the same country or multiple songs by the same artist. This data is stored lexicographically. The combination of a partition key (PK) and range key (RK) must be unique, but queries that only specify the PK will retrieve all the information related to that key ordered. The range key is an internal sorted index of the table.

In our new design the Music table now has a range key that will be used to find items related with an explicit partition key, in our example, the PK is the British band Queen:

The Query operation specifies the Queen string attribute as the partition key, DynamoDB will perform a hash operation to determine the partition where this data is stored f(x) = P. The read operation will use the range key to find the associated data with the PK and retrieve the ordered items.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.150.231