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.
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.
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.
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.
note: Here is hardcoded API Gateway URL
|
Thank you for your contribution and sorry for the delay. There was an update in the meantime which targeted the same issue. |
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.