Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions lambda-durable-hitl-python-sam/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Virtual environments
venv/
ENV/
env/
.venv

# Testing
.pytest_cache/
.coverage
htmlcov/
.hypothesis/
*.cover
.tox/

# IDEs
.vscode/
.idea/
*.swp
*.swo
*~

# AWS SAM
.aws-sam/
samconfig.toml

# Logs
*.log

# OS
.DS_Store
Thumbs.db

# Environment variables
.env
.env.local
504 changes: 504 additions & 0 deletions lambda-durable-hitl-python-sam/README.md
Comment thread
4D54 marked this conversation as resolved.

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions lambda-durable-hitl-python-sam/example-pattern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"title": "Lambda Durable Functions with Human-in-the-Loop",
"description": "Demonstrates Lambda durable functions with human approval workflow using Python 3.13, DynamoDB, and SNS",
"language": "Python",
"level": "300",
"framework": "SAM",
"introBox": {
"headline": "How it works",
"text": [
"This pattern demonstrates how to pause Lambda execution, wait for human approval, and resume using the Lambda durable functions SDK.",
"The Workflow Lambda creates an approval request in DynamoDB and polls for decisions using durable waits (no compute charges during waits).",
"An SNS notification is sent to approvers, who can submit their decision via the Approval API Lambda function.",
"The Workflow Lambda detects the decision during polling and resumes execution with the approval result.",
"The pattern includes timeout handling, status tracking, and a complete audit trail of all approval decisions."
]
},
"gitHub": {
"template": {
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/lambda-durable-hitl-python-sam",
"templateURL": "serverless-patterns/lambda-durable-hitl-python-sam",
"projectFolder": "lambda-durable-hitl-python-sam",
"templateFile": "template.yaml"
}
},
"resources": {
"bullets": [
{
"text": "Lambda Durable Functions Documentation",
"link": "https://docs.aws.amazon.com/lambda/latest/dg/durable-functions.html"
},
{
"text": "AWS SAM Documentation",
"link": "https://docs.aws.amazon.com/serverless-application-model/"
},
{
"text": "DynamoDB Best Practices",
"link": "https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/best-practices.html"
},
{
"text": "Amazon SNS Documentation",
"link": "https://docs.aws.amazon.com/sns/"
}
]
},
"deploy": {
"text": [
"sam build",
"sam deploy --guided"
]
},
"testing": {
"text": [
"See the README in the GitHub repo for detailed testing instructions.",
"Test the approval workflow using AWS CLI:",
"1. Publish Lambda version: aws lambda publish-version --function-name <WorkflowFunction>",
"2. Invoke workflow: aws lambda invoke --function-name <WorkflowFunction>:<version> --invocation-type Event --payload '{...}' response.json",
"3. List approvals: aws dynamodb scan --table-name <ApprovalsTable>",
"4. Submit decision: aws lambda invoke --function-name <ApprovalApiFunction> --payload '{\"action\":\"decide\",...}' response.json"
]
},
"cleanup": {
"text": [
"Delete the stack: sam delete"
]
},
"authors": [
{
"name": "Mian Tariq",
"bio": "Cloud Solutions Architect"
}
],
"patternArch": {
"icon1": {
"name": "lambda",
"label": "Lambda Durable Functions"
},
"icon2": {
"name": "dynamodb",
"label": "Amazon DynamoDB"
},
"icon3": {
"name": "sns",
"label": "Amazon SNS"
}
}
}
14 changes: 14 additions & 0 deletions lambda-durable-hitl-python-sam/src/approval_api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM public.ecr.aws/lambda/python:3.13

# Copy requirements file
COPY approval_api/requirements.txt ${LAMBDA_TASK_ROOT}/

# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy function code
COPY approval_api/app.py ${LAMBDA_TASK_ROOT}/
COPY shared/*.py ${LAMBDA_TASK_ROOT}/

# Set the CMD to your handler
CMD ["app.lambda_handler"]
Loading