A DynamoDB item is one record in a table, comparable to a row in a relational database. It is a collection of attributes, and each attribute is a name-value pair. Attribute values may be scalar, multivalued, or JSON documents. section 12.1 section 12.2
Keep these characteristics in mind when designing and using items:
- Allow items in one table to have different non-key attributes because DynamoDB does not enforce a fixed schema. section 12.2
- Define the primary-key attributes because the key uniquely identifies an item and supports retrieval, updates, and deletion. section 12.2.1
- Use either a partition key alone or a partition key combined with a sort key, depending on the table design. section 12.2.1 section 12.4.1
- Send item operations through the AWS SDK and DynamoDB API rather than treating the table like a SQL database. section 12.1 section 12.3
A user item
A user item in the todo-user table can contain uid, email, and phone attributes. With uid as the partition key, getItem retrieves Emma by supplying uid set to emma; a task item can instead use both uid and tid. section 12.2.1 section 12.4.1
Listing 12.4 DynamoDB: Creating an item
const params = {
Item: { #1
attr1: {S: 'val1'}, #2
attr2: {N: '2'} #3
},
TableName: 'app-entity' #4
};
db.putItem(params, (err) => { #5
if (err) { #6
console.error('error', err);
} else {
console.log('success');
}
});
See the smallest AWS SDK request for creating an item: provide an Item map, typed attribute values, and a table name, then call putItem. section 12.3
