Skip to content

Commit 8ba7662

Browse files
committed
lambda-durable-human-approval-sam: Fix hardcoded API Gateway URL by using environment variable
1 parent 2a31c14 commit 8ba7662

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

lambda-durable-human-approval-sam/src/lambda_function.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ def lambda_handler(event, context: DurableContext):
2929
description = body.get('description', 'No description')
3030

3131
# Get API Gateway URL from environment or construct it
32-
region = os.environ.get('AWS_REGION', 'us-east-2')
33-
api_base_url = f"https://w8a9tempjb.execute-api.{region}.amazonaws.com/prod"
32+
api_base_url = os.environ['API_BASE_URL']
3433

3534
print(f"Starting approval workflow for request: {request_id}")
3635
print(f"API Base URL: {api_base_url}")

lambda-durable-human-approval-sam/template.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Resources:
3636
CallbackHandlerFunction:
3737
Type: AWS::Serverless::Function
3838
Properties:
39+
FunctionName: !Sub '${AWS::StackName}-CallbackHandlerFunction'
3940
CodeUri: src/
4041
Handler: callback_handler.lambda_handler
4142
Runtime: python3.14
@@ -56,6 +57,7 @@ Resources:
5657
ApprovalFunction:
5758
Type: AWS::Serverless::Function
5859
Properties:
60+
FunctionName: !Sub '${AWS::StackName}-ApprovalFunction'
5961
CodeUri: src/
6062
Handler: lambda_function.lambda_handler
6163
Runtime: python3.14
@@ -68,6 +70,7 @@ Resources:
6870
Variables:
6971
APPROVAL_TOPIC_ARN: !Ref ApprovalTopic
7072
CALLBACK_TABLE_NAME: !Ref CallbackTable
73+
API_BASE_URL: !Sub 'https://${ApprovalApi}.execute-api.${AWS::Region}.amazonaws.com/prod'
7174
Policies:
7275
- SNSPublishMessagePolicy:
7376
TopicName: !GetAtt ApprovalTopic.TopicName
@@ -134,7 +137,7 @@ Resources:
134137
x-amazon-apigateway-integration:
135138
type: aws
136139
httpMethod: POST
137-
uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApprovalFunction.Arn}:live/invocations'
140+
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'
138141
requestParameters:
139142
integration.request.header.X-Amz-Invocation-Type: "'Event'"
140143
responses:

0 commit comments

Comments
 (0)