Step Functions help you organize tasks in order, and DynamoDB stores your data safely. Together, they let you automate processes that need to save or get data step by step.
0
0
Step Functions with DynamoDB
Introduction
You want to process a user order and save each step's result in DynamoDB.
You need to update inventory counts after each sale automatically.
You want to run a multi-step approval process and record decisions in DynamoDB.
You need to handle retries or errors when saving data to DynamoDB.
You want to chain tasks that read and write data in DynamoDB without writing complex code.
Syntax
DynamoDB
{
"StartAt": "TaskName",
"States": {
"TaskName": {
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:putItem",
"Parameters": {
"TableName": "YourTableName",
"Item": {
"PrimaryKey": {"S": "Value"},
"Attribute": {"S": "Value"}
}
},
"End": true
}
}
}The Resource field specifies the DynamoDB action like putItem or getItem.
Parameters define the table and data you want to work with.
Examples
This example saves a new order with ID 123 and status Pending into the Orders table.
DynamoDB
{
"StartAt": "SaveData",
"States": {
"SaveData": {
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:putItem",
"Parameters": {
"TableName": "Orders",
"Item": {
"OrderId": {"S": "123"},
"Status": {"S": "Pending"}
}
},
"End": true
}
}
}This example reads the order with ID 123 from the Orders table.
DynamoDB
{
"StartAt": "GetData",
"States": {
"GetData": {
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:getItem",
"Parameters": {
"TableName": "Orders",
"Key": {
"OrderId": {"S": "123"}
}
},
"End": true
}
}
}Sample Program
This Step Function first saves an order with ID 001 and status Created, then reads it back from DynamoDB.
DynamoDB
{
"StartAt": "SaveOrder",
"States": {
"SaveOrder": {
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:putItem",
"Parameters": {
"TableName": "Orders",
"Item": {
"OrderId": {"S": "001"},
"Status": {"S": "Created"}
}
},
"Next": "GetOrder"
},
"GetOrder": {
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:getItem",
"Parameters": {
"TableName": "Orders",
"Key": {
"OrderId": {"S": "001"}
}
},
"End": true
}
}
}OutputSuccess
Important Notes
Make sure your Step Function has permission to access DynamoDB tables.
Use Next to chain multiple DynamoDB operations in order.
Step Functions handle retries automatically if DynamoDB calls fail.
Summary
Step Functions let you run tasks in order, like saving or reading data.
DynamoDB stores your data safely and quickly.
Together, they automate workflows that need data storage and retrieval step by step.