Key Concepts

The DynamoDB data model concepts include tables, items, and attributes.

Tables

In Amazon DynamoDB, a database is a collection of tables. A table is a collection
of items and each
item is a collection of attributes.

In a relational database, a table has a predefined schema such as the table name,
primary key, list
of its column names and their data types. All records stored in the table must have
the same set of
columns. In contrast, DynamoDB only requires that a table has a primary key, but does
not require
you to define all of the attribute names and data types in advance.

Items and Attributes

Individual items in a DynamoDB table can have any number of attributes, although there
is a limit of
400 KB on the item size. An item size is the sum of lengths of its attribute names
and values
(binary and UTF-8 lengths).

Each attribute in an item is a name-value pair. An attribute can be single-valued
or multi-valued
set. For example, a book item can have title and authors attributes. Each book has
one title but can
have many authors. The multi-valued attribute is a set; duplicate values are not allowed.

For example, consider storing a catalog of products in DynamoDB. You can create a
table,
ProductCatalog, with the Id attribute as its primary key. The primary key uniquely
identifies each
item, so that no two products in the table can have the same ID.

Primary Key

When you create a table, in addition to the table name, you must specify the primary
key of the
table. The primary key uniquely identifies each item in the table, so that no two
items can have the
same key. DynamoDB supports the following two types of primary keys:

Hash Key: The primary key is made of one attribute, a hash attribute. DynamoDB builds an
unordered hash index on this primary key attribute. Each item in the table is uniquely
identified
by its hash key value.

Hash and Range Key: The primary key is made of two attributes. The first attribute is the hash
attribute and the second one is the range attribute. DynamoDB builds an unordered
hash index on
the hash primary key attribute, and a sorted range index on the range primary key
attribute. Each
item in the table is uniquely identified by the combination of its hash and range
key values. It
is possible for two items to have the same hash key value, but those two items must
have different
range key values.

Secondary Indexes

When you create a table with a hash and range key, you can optionally define one or
more secondary
indexes on that table. A secondary index lets you query the data in the table using
an alternate
key, in addition to queries against the primary key.

Query and Scan

In addition to using primary keys to access items, Amazon DynamoDB also provides two
APIs for
searching the data: Query and Scan. We recommend that you read Guidelines for Query and Scan in
the DynamoDB Developer Guide to familiarize yourself with some best practices.

Query

A Query operation finds items in a table or a secondary index using only primary key
attribute
values. You must provide a hash key attribute name and a distinct value to search
for. You can
optionally provide a range key attribute name and value, and use a comparison operator
to refine the
search results.

For more information on Query, see Query
in the DynamoDB Developer Guide.

Scan

A Scan operation reads every item in a table or a secondary index. By default, a Scan
operation
returns all of the data attributes for every item in the table or index. You can use
the
ProjectionExpression parameter so that Scan only returns some of the attributes, rather
than all of
them.

Create a DynamoDB Table

Select a type and enter a value for the hash attribute name. Click Continue.

On the Add Indexes page, if you plan to to use global secondary indexes, set Index Type
to "Global Secondary Index" and under Index Hash Key, enter a value for the secondary index.
This will allow you to query and scan using both the primary index and secondary index.
Click
Add Index To Table, and then click Continue. To skip using global secondary
indexes, click Continue.

Set Permissions for DynamoDB

To use DynamoDB in an application, you must set the correct permissions. The following
IAM policy
allows the user to delete, get, put, query, scan, and update items in a specific DynamoDB
table,
which is identified by ARN:

Integrating DynamoDB with your Application

The AWS Mobile SDK for .NET and Xamarin provides a high-level library for working
with DynamoDB. You can also make
requests directly against the low-level DynamoDB API, but for most use cases the high-level
library
is recommended. The AmazonDynamoDBClient is an especially useful part of the high-level
library.
Using this class, you can perform various create, read, update, and delete (CRUD)
operations and
execute queries.

The AWS Mobile SDK for .NET and Xamarin allows you to make calls using APIs from the
AWS SDK for .NET to work with
DynamoDB. All of the APIs are available in the AWSSDK.dll. For information about downloading
the AWS
SDK for .NET, see AWS SDK for .NET.

There are three ways you can interact with DynamoDB in your Xamarin application:

Document Model: This API provides wrapper classes around the low-level DyanmoDB API to further
simplify your programming tasks. The Table and Document are the key wrapper classes.
You can use
the document model for the data operations such as create, retrieve, update and delete
items. The
API is available in the Amazon.DynamoDB.DocumentModel namespace.

Object Persistence Model: The Object Persistence API enables you to map your client-side
classes to the DynamoDB tables. Each object instance then maps to an item in the corresponding
tables. The DynamoDBContext class in this API provides methods for you to save client-side
objects
to a table, retrieve items as objects and perform query and scan. You can use the
Object
Persistence model for the data operations such as create, retrieve, update and delete
items. You
must first create your tables using the Service Client API and then use the object
persistence
model to map your classes to the tables. The API is available in the Amazon.DynamoDB.DataModel
namespace.

Service Client API: This is the protocol-level API that maps closely to the DynamoDB API. You
can use this low-level API for all table and item operations such as create, update,
delete table
and items. You can also query and scan your tables. This API is available in the Amazon.DynamoDB
namespace.