checkInventory
export const handler = async (event) => {
console.log("Checking inventory for order:", event.orderId);
// Simulate inventory check
const inStock = Math.random() < 0.9;
return {
orderId: event.orderId,
inStock: inStock
};
};
processPayment
export const handler = async (event) => {
console.log("Processing payment for order:", event.orderId);
// Simulate payment processing
const paymentSuccessful = Math.random() < 0.9;
return {
orderId: event.orderId,
paymentSuccessful: paymentSuccessful
};
};
updateOrderStatus
export const handler = async (event) => {
console.log("Updating status for order:", event.orderId);
// Simulate order status update
return {
orderId: event.orderId,
status: "Completed"
};
};
{
"Comment": "A simple order processing workflow",
"StartAt": "Check Inventory",
"States": {
"Check Inventory": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:211125437318:function:checkInventory",
"Next": "Is In Stock?"
},
"Is In Stock?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.inStock",
"BooleanEquals": true,
"Next": "Process Payment"
}
],
"Default": "Out of Stock"
},
"Process Payment": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:211125437318:function:processPayment",
"Next": "Payment Successful?"
},
"Payment Successful?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.paymentSuccessful",
"BooleanEquals": true,
"Next": "Update Order Status"
}
],
"Default": "Payment Failed"
},
"Update Order Status": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:211125437318:function:updateOrderStatus",
"End": true
},
"Out of Stock": {
"Type": "Fail",
"Cause": "Item is out of stock",
"Error": "OutOfStockError"
},
"Payment Failed": {
"Type": "Fail",
"Cause": "Payment processing failed",
"Error": "PaymentError"
}
}
}
MAKE SURE TO REPLACE THE AWS LAMBDA ARN
{
"orderId": "12345"
}
StepFunc