Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions lambda-durable-human-approval-sam/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This pattern demonstrates a human-in-the-loop approval workflow using AWS Lambda

**Important:** Please check the [AWS documentation](https://docs.aws.amazon.com/lambda/latest/dg/durable-functions.html) for regions currently supported by AWS Lambda durable functions.

Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/lambda-durable-hitl-approval-sam
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: It's wrong url

Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/lambda-durable-human-approval-sam

## Architecture

Expand Down Expand Up @@ -44,7 +44,7 @@ The pattern uses Lambda durable functions to implement a cost-effective approval

1. Navigate to the pattern directory:
```bash
cd lambda-durable-hitl-approval-sam
cd lambda-durable-human-approval-sam
```

2. Build the SAM application:
Expand Down Expand Up @@ -197,14 +197,14 @@ sam deploy --parameter-overrides ApproverEmail=new-email@example.com

Monitor the durable function:
```bash
aws logs tail /aws/lambda/lambda-durable-hitl-approval-ApprovalFunction-XXXXX \
aws logs tail /aws/lambda/lambda-durable-human-approval-ApprovalFunction \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Update CloudWatch Logs log group name because I set FunctionName in SAM template

--region us-east-2 \
--follow
```

Monitor the callback handler:
```bash
aws logs tail /aws/lambda/lambda-durable-hitl-approv-CallbackHandlerFunction-XXXXX \
aws logs tail /aws/lambda/lambda-durable-human-approval-CallbackHandlerFunction \
--region us-east-2 \
--follow
```
Expand All @@ -214,7 +214,7 @@ aws logs tail /aws/lambda/lambda-durable-hitl-approv-CallbackHandlerFunction-XXX
## Cleanup

```bash
sam delete --stack-name lambda-durable-hitl-approval --region us-east-2
sam delete --stack-name lambda-durable-human-approval --region us-east-2
```


Expand Down
3 changes: 1 addition & 2 deletions lambda-durable-human-approval-sam/src/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def lambda_handler(event, context: DurableContext):
description = body.get('description', 'No description')

# Get API Gateway URL from environment or construct it
region = os.environ.get('AWS_REGION', 'us-east-2')
api_base_url = f"https://w8a9tempjb.execute-api.{region}.amazonaws.com/prod"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Here is hardcoded API Gateway URL

api_base_url = os.environ['API_BASE_URL']

print(f"Starting approval workflow for request: {request_id}")
print(f"API Base URL: {api_base_url}")
Expand Down
5 changes: 4 additions & 1 deletion lambda-durable-human-approval-sam/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Resources:
CallbackHandlerFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub '${AWS::StackName}-CallbackHandlerFunction'
CodeUri: src/
Handler: callback_handler.lambda_handler
Runtime: python3.14
Expand All @@ -56,6 +57,7 @@ Resources:
ApprovalFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub '${AWS::StackName}-ApprovalFunction'
CodeUri: src/
Handler: lambda_function.lambda_handler
Runtime: python3.14
Expand All @@ -68,6 +70,7 @@ Resources:
Variables:
APPROVAL_TOPIC_ARN: !Ref ApprovalTopic
CALLBACK_TABLE_NAME: !Ref CallbackTable
API_BASE_URL: !Sub 'https://${ApprovalApi}.execute-api.${AWS::Region}.amazonaws.com/prod'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: To pass the API_BASE_URL environment variable to the Lambda function, we needed to resolve a circular dependency between the Lambda function and API Gateway. To break this cycle, we explicitly set the Lambda FunctionName and manually constructed the ARN in the API Gateway integration URI. This reduces the dependency to a one-way reference from the Lambda function to API Gateway, resolving the circular dependency😀

Policies:
- SNSPublishMessagePolicy:
TopicName: !GetAtt ApprovalTopic.TopicName
Expand Down Expand Up @@ -134,7 +137,7 @@ Resources:
x-amazon-apigateway-integration:
type: aws
httpMethod: POST
uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApprovalFunction.Arn}:live/invocations'
uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${AWS::StackName}-ApprovalFunction:live/invocations'
requestParameters:
integration.request.header.X-Amz-Invocation-Type: "'Event'"
responses:
Expand Down