📖 Scenario: You are building a simple cloud database to store and retrieve user profiles. Each profile has a unique user ID, a name, and an email address. You will create the data structure, configure a key for queries, add data, and then retrieve data using put, get, and query operations.
🎯 Goal: Build a simple AWS DynamoDB table setup with put, get, and query operations to store and retrieve user profiles by user ID.
📋 What You'll Learn
Create a DynamoDB table named UserProfiles with UserID as the primary key
Add a configuration variable for the table name
Write a put operation to add a user profile with UserID, Name, and Email
Write a get operation to retrieve a user profile by UserID
Write a query operation to find user profiles by UserID
💡 Why This Matters
🌍 Real World
Cloud databases like DynamoDB are used to store user data for web and mobile apps. Knowing how to put, get, and query data is essential for building responsive applications.
💼 Career
These operations are fundamental skills for cloud engineers, backend developers, and anyone working with AWS cloud services.
Progress0 / 4 steps
1
Create DynamoDB table data structure
Create a dictionary called table_definition that defines a DynamoDB table named UserProfiles with a primary key attribute called UserID of type string.
AWS
Hint
Think of table_definition as a blueprint for your database table. You need to specify the table name and the key structure.
2
Add configuration variable for table name
Create a variable called table_name and set it to the string 'UserProfiles'.
AWS
Hint
This variable will help you refer to the table easily in your code.
3
Write put operation to add a user profile
Write a dictionary called put_item that represents a DynamoDB put operation to add a user profile with UserID set to 'user123', Name set to 'Alice', and Email set to 'alice@example.com'.
AWS
Hint
Use the Item key to specify the data you want to add. Each attribute needs its type specified as 'S' for string.
4
Write get and query operations to retrieve user profile
Write two dictionaries: get_item to get a user profile by UserID set to 'user123', and query_item to query the table for items where UserID equals 'user123'.
AWS
Hint
Use Key for get operations and KeyConditionExpression with ExpressionAttributeValues for query operations.
Practice
(1/5)
1. What does the put operation do in AWS DynamoDB?
easy
A. Saves or updates an item in the table
B. Retrieves a single item by its key
C. Searches items based on key conditions
D. Deletes an item from the table
Solution
Step 1: Understand the purpose of put
The put operation is used to save a new item or update an existing item in a DynamoDB table.
Step 2: Compare with other operations
get retrieves one item by key, query searches by key conditions, and delete removes an item.
Final Answer:
Saves or updates an item in the table -> Option A
Quick Check:
Put = Save or update [OK]
Hint: Put means save or update data [OK]
Common Mistakes:
Confusing put with get or query
Thinking put deletes data
Assuming put only adds new items
2. Which of the following is the correct syntax to get an item by its key in AWS SDK for JavaScript DynamoDB client?
easy
A. dynamoDBClient.put({ TableName: 'MyTable', Item: { id: '123' } })
B. dynamoDBClient.get({ TableName: 'MyTable', Key: { id: '123' } })
C. dynamoDBClient.query({ TableName: 'MyTable', KeyConditionExpression: 'id = :id' })
D. dynamoDBClient.getItem({ TableName: 'MyTable', Key: { id: '123' } })
Solution
Step 1: Identify the correct method for getting an item
The AWS SDK for JavaScript v3 uses get method on the DynamoDB DocumentClient to retrieve a single item by key.
Step 2: Check the parameters
The parameters include TableName and Key with the key attribute and value.