-
Notifications
You must be signed in to change notification settings - Fork 1k
lambda-durable-human-approval-sam: Fix hardcoded API Gateway URL by using environment variable #2921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
lambda-durable-human-approval-sam: Fix hardcoded API Gateway URL by using environment variable #2921
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/lambda-durable-human-approval-sam | ||
|
|
||
| ## Architecture | ||
|
|
||
|
|
@@ -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: | ||
|
|
@@ -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 \ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: Update CloudWatch Logs log group name because I set |
||
| --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 | ||
| ``` | ||
|
|
@@ -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 | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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 | ||
|
|
@@ -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' | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: To pass the |
||
| Policies: | ||
| - SNSPublishMessagePolicy: | ||
| TopicName: !GetAtt ApprovalTopic.TopicName | ||
|
|
@@ -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: | ||
|
|
||
There was a problem hiding this comment.
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