-
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
Conversation
|
|
||
| **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 |
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
| 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 \ |
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: Update CloudWatch Logs log group name because I set FunctionName in SAM template
| Variables: | ||
| APPROVAL_TOPIC_ARN: !Ref ApprovalTopic | ||
| CALLBACK_TABLE_NAME: !Ref CallbackTable | ||
| API_BASE_URL: !Sub 'https://${ApprovalApi}.execute-api.${AWS::Region}.amazonaws.com/prod' |
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: 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😀
|
|
||
| # 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" |
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: Here is hardcoded API Gateway URL
Issue #, if available:
N/A
Description of changes:
Hi😀 Thanks for the useful patterns!
While testing lambda-durable-human-approval-sam, I could not access to the Approval URL because url was hardcoded in Python code like below.
Check
I fixed it using environment variable and it works good 👍
Thank you😀
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.