Below are updated THEORY notes and IMPORTANT POINTS TO REMEMBER for DynamoDB CRUD operations using Boto3, written in a clear, exam-oriented format.
Amazon DynamoDB is a fully managed NoSQL key–value and document database service provided by AWS. It offers single-digit millisecond performance, automatic scaling, and high availability.
Boto3 is the official AWS SDK for Python that allows developers to interact with AWS services programmatically.
CRUD operations represent the four basic database operations:
- Create – Insert an item into the table
- Read – Retrieve an item using primary key
- Update – Modify existing item attributes
- Delete – Remove an item from the table
In DynamoDB, every operation is performed using the primary key, which can be:
- Partition key only, or
- Partition key + Sort key
- Performed using
put_item() - Inserts a new item or replaces an existing item with the same primary key
- Item must contain the primary key attribute
table.put_item(Item={...})- Performed using
get_item() - Retrieves an item based on primary key
- If item does not exist, response will not contain
Item
table.get_item(Key={...})- Performed using
update_item() - Updates one or more attributes without replacing the entire item
- Uses UpdateExpression
UpdateExpression="SET attribute = :value"- Performed using
delete_item() - Deletes an item using its primary key
table.delete_item(Key={...})- DynamoDB is schema-less (except primary key)
- It is a NoSQL database
- Data is stored as items and attributes
- Tables are region-specific
- Primary key is mandatory
- Operations always require primary key
- Supports Global Secondary Index (GSI) and Local Secondary Index (LSI)
boto3.resource('dynamodb')→ high-level interfaceboto3.client('dynamodb')→ low-level interfaceTable('TableName')gives table object
| Operation | Method | Key Requirement |
|---|---|---|
| Create | put_item() |
Primary key required |
| Read | get_item() |
Primary key required |
| Update | update_item() |
Primary key required |
| Delete | delete_item() |
Primary key required |
- Must use placeholders (
:value) - Prevents injection issues
- Supports
SET,REMOVE,ADD
- Provisioned (RCU/WCU specified)
- On-Demand (auto scaling)
-
IAM permissions required:
dynamodb:PutItemdynamodb:GetItemdynamodb:UpdateItemdynamodb:DeleteItem
-
Credentials must be configured
- DynamoDB is serverless and fully managed
- CRUD operations are key-based
- Boto3 enables programmatic AWS access
put_item()replaces item if key exists
- Removed global complexity
- Clear function names
- Single primary key (common in exams)
- Minimal error handling
- Clean menu-driven program
- Easy to modify and understand
import boto3
# Create DynamoDB resource
dynamodb = boto3.resource('dynamodb')
# Change table name as required
TABLE_NAME = "StudentTable"
table = dynamodb.Table(TABLE_NAME)
# CREATE (Insert Item)
def create_item():
roll = input("Enter Roll No: ")
name = input("Enter Name: ")
marks = int(input("Enter Marks: "))
table.put_item(
Item={
'RollNo': roll,
'Name': name,
'Marks': marks
}
)
print("Item inserted successfully")
# READ (Get Item)
def read_item():
roll = input("Enter Roll No: ")
response = table.get_item(
Key={'RollNo': roll}
)
if 'Item' in response:
print("Item Found:", response['Item'])
else:
print("Item not found")
# UPDATE (Update Item)
def update_item():
roll = input("Enter Roll No: ")
new_marks = int(input("Enter new Marks: "))
table.update_item(
Key={'RollNo': roll},
UpdateExpression="SET Marks = :m",
ExpressionAttributeValues={
':m': new_marks
}
)
print("Item updated successfully")
# DELETE (Delete Item)
def delete_item():
roll = input("Enter Roll No: ")
table.delete_item(
Key={'RollNo': roll}
)
print("Item deleted successfully")
# MENU
def menu():
while True:
print("\n--- DynamoDB CRUD Menu ---")
print("1. Insert Item")
print("2. Get Item")
print("3. Update Item")
print("4. Delete Item")
print("5. Exit")
choice = input("Enter choice: ")
if choice == '1':
create_item()
elif choice == '2':
read_item()
elif choice == '3':
update_item()
elif choice == '4':
delete_item()
elif choice == '5':
break
else:
print("Invalid choice")
# MAIN
if __name__ == "__main__":
menu()- Table Name:
StudentTable - Primary Key:
RollNo(String)
- Create:
put_item()inserts a new record - Read:
get_item()fetches data using primary key - Update:
update_item()modifies attributes - Delete:
delete_item()removes item using key
- Marks-wise answer
- Serverless version
- Exception-free version
- Diagram + explanation
Just tell me 👍