Bird
Raised Fist0
AWScloud~5 mins

Tables, items, and attributes in AWS - Commands & Configuration

Choose your learning style10 modes available
Introduction
When you want to store data in a way that is easy to find and update, you use tables. Tables hold items, which are like rows in a spreadsheet. Each item has attributes, which are like the columns or details about that item.
When you need to save user profiles with different details like name, age, and email.
When you want to keep track of orders in an online store with order ID, date, and status.
When you want to store settings for an app where each setting has a name and value.
When you want to quickly find data by a unique key like a user ID or product code.
When you want a flexible way to add or remove details without changing the whole structure.
Config File - table-definition.json
table-definition.json
{
  "TableName": "Users",
  "AttributeDefinitions": [
    {
      "AttributeName": "UserID",
      "AttributeType": "S"
    }
  ],
  "KeySchema": [
    {
      "AttributeName": "UserID",
      "KeyType": "HASH"
    }
  ],
  "ProvisionedThroughput": {
    "ReadCapacityUnits": 5,
    "WriteCapacityUnits": 5
  }
}

This file defines a DynamoDB table named Users. It has one attribute called UserID which is a string (S).

The KeySchema says UserID is the primary key to find items quickly.

ProvisionedThroughput sets how many reads and writes the table can handle per second.

Commands
This command creates the DynamoDB table using the definition in the JSON file.
Terminal
aws dynamodb create-table --cli-input-json file://table-definition.json
Expected OutputExpected
{ "TableDescription": { "TableName": "Users", "TableStatus": "CREATING", "ProvisionedThroughput": { "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 }, "TableSizeBytes": 0, "ItemCount": 0, "KeySchema": [ { "AttributeName": "UserID", "KeyType": "HASH" } ], "AttributeDefinitions": [ { "AttributeName": "UserID", "AttributeType": "S" } ], "TableArn": "arn:aws:dynamodb:us-east-1:123456789012:table/Users" } }
→
--cli-input-json - Specifies the JSON file with the table definition
This command waits until the table is fully created and ready to use.
Terminal
aws dynamodb wait table-exists --table-name Users
Expected OutputExpected
No output (command runs silently)
→
--table-name - Specifies the name of the table to wait for
This command adds an item to the Users table with UserID, Name, and Age attributes.
Terminal
aws dynamodb put-item --table-name Users --item '{"UserID": {"S": "user123"}, "Name": {"S": "Alice"}, "Age": {"N": "30"}}'
Expected OutputExpected
No output (command runs silently)
→
--table-name - Specifies the table to add the item to
→
--item - Defines the item attributes and their types
This command retrieves the item with UserID 'user123' from the Users table.
Terminal
aws dynamodb get-item --table-name Users --key '{"UserID": {"S": "user123"}}'
Expected OutputExpected
{ "Item": { "UserID": {"S": "user123"}, "Name": {"S": "Alice"}, "Age": {"N": "30"} } }
→
--table-name - Specifies the table to get the item from
→
--key - Defines the primary key of the item to retrieve
Key Concept

If you remember nothing else from this pattern, remember: tables hold items, and items have attributes that store your data.

Common Mistakes
Trying to add an item without specifying the primary key attribute.
DynamoDB requires the primary key to find and store items uniquely; missing it causes an error.
Always include the primary key attribute with the correct type when adding items.
Using incorrect attribute types like putting a number as a string without the right format.
DynamoDB expects attribute types to match exactly; wrong types cause failures or wrong data storage.
Use "S" for strings and "N" for numbers with values as strings, e.g., "Age": {"N": "30"}.
Not waiting for the table to be active before adding items.
If the table is still creating, adding items will fail because the table is not ready.
Use the wait command to ensure the table is active before inserting data.
Summary
Create a DynamoDB table by defining its name, primary key, and capacity in a JSON file.
Use the AWS CLI to create the table and wait until it is ready.
Add items with attributes to the table using the put-item command.
Retrieve items by their primary key using the get-item command.

Practice

(1/5)
1. What is the main purpose of a table in AWS DynamoDB?
easy
A. To store items, which are records
B. To run code functions
C. To manage user permissions
D. To host websites

Solution

  1. Step 1: Understand the role of a table in DynamoDB

    A table is a container that holds items, which are like rows in a database.
  2. Step 2: Identify the correct purpose

    Since tables store items (records), this matches To store items, which are records.
  3. Final Answer:

    To store items, which are records -> Option A
  4. Quick Check:

    Table = container for items [OK]
Hint: Tables hold records called items [OK]
Common Mistakes:
  • Confusing tables with code functions
  • Thinking tables manage permissions
  • Assuming tables host websites
2. Which of the following is the correct way to define an item attribute in DynamoDB?
easy
A. ("Name", "John", "Age", 30)
B. {"Name": "John", "Age": 30}
C. ["Name", "John", "Age", 30]
D. "Name": "John", "Age": 30

Solution

  1. Step 1: Recognize the attribute format

    Attributes are key-value pairs, best represented as JSON objects with keys and values.
  2. Step 2: Match the correct syntax

    {"Name": "John", "Age": 30} shows a JSON object with keys "Name" and "Age" and their values, which is correct.
  3. Final Answer:

    {"Name": "John", "Age": 30} -> Option B
  4. Quick Check:

    Attributes = key-value pairs in JSON [OK]
Hint: Attributes are key-value pairs in JSON format [OK]
Common Mistakes:
  • Using arrays instead of key-value pairs
  • Using tuples instead of objects
  • Omitting braces for JSON objects
3. Given a DynamoDB table with primary key "UserID", what happens if you try to add two items with the same UserID but different attributes?
medium
A. Both items are stored separately
B. The table creates a duplicate primary key
C. An error is thrown and no item is added
D. The second item overwrites the first item

Solution

  1. Step 1: Understand primary key uniqueness

    In DynamoDB, the primary key must be unique for each item in the table.
  2. Step 2: Effect of duplicate primary key

    If you add an item with an existing primary key, it replaces the old item with the new one.
  3. Final Answer:

    The second item overwrites the first item -> Option D
  4. Quick Check:

    Duplicate key = overwrite existing item [OK]
Hint: Duplicate primary keys overwrite existing items [OK]
Common Mistakes:
  • Thinking both items are stored separately
  • Expecting an error on duplicate keys
  • Assuming duplicates are allowed
4. You try to insert an item into a DynamoDB table but get an error. The item has no primary key attribute. What is the most likely cause?
medium
A. Missing required primary key attribute in the item
B. Table is full and cannot accept new items
C. Attributes have invalid data types
D. You exceeded the maximum number of attributes

Solution

  1. Step 1: Recall primary key requirement

    Every item must have the primary key attribute to be uniquely identified in the table.
  2. Step 2: Identify cause of error

    If the item lacks the primary key attribute, DynamoDB rejects it with an error.
  3. Final Answer:

    Missing required primary key attribute in the item -> Option A
  4. Quick Check:

    Primary key missing causes insert error [OK]
Hint: Every item must include the primary key attribute [OK]
Common Mistakes:
  • Assuming table capacity causes insert errors
  • Blaming attribute data types without checking keys
  • Thinking attribute count limits cause this error
5. You want to design a DynamoDB table to store user profiles. Each user has a unique UserID and may have multiple email addresses. How should you structure the table and items to handle this?
hard
A. Use email as the primary key and ignore UserID
B. Use UserID as the primary key and create a separate item for each email
C. Use UserID as the primary key and store emails as a list attribute inside each item
D. Create multiple tables, one per email address

Solution

  1. Step 1: Identify unique identifier

    UserID uniquely identifies each user, so it should be the primary key.
  2. Step 2: Store multiple emails

    Since a user can have multiple emails, store them as a list attribute inside the user item.
  3. Step 3: Evaluate other options

    Creating separate items per email duplicates UserID or loses uniqueness; using email as key ignores UserID; multiple tables is inefficient.
  4. Final Answer:

    Use UserID as the primary key and store emails as a list attribute inside each item -> Option C
  5. Quick Check:

    Primary key + list attribute for multiple values [OK]
Hint: Use primary key for user, list attribute for multiple emails [OK]
Common Mistakes:
  • Using email as primary key instead of UserID
  • Creating multiple items for one user
  • Making multiple tables unnecessarily
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard