File tree Expand file tree Collapse file tree
lambda-durable-human-approval-sam Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,10 +28,18 @@ def lambda_handler(event, context: DurableContext):
2828 amount = body .get ('amount' , 0 )
2929 description = body .get ('description' , 'No description' )
3030
31- # Get API Gateway URL from environment variable
32- api_base_url = os .environ .get ('API_BASE_URL' )
33- if not api_base_url :
34- raise ValueError ("API_BASE_URL environment variable is not set" )
31+ # Get API Gateway URL from Parameter Store
32+ param_name = os .environ .get ('API_GATEWAY_PARAM' )
33+ if not param_name :
34+ raise ValueError ("API_GATEWAY_PARAM environment variable is not set" )
35+
36+ try :
37+ import boto3
38+ ssm = boto3 .client ('ssm' )
39+ response = ssm .get_parameter (Name = param_name )
40+ api_base_url = response ['Parameter' ]['Value' ]
41+ except Exception as e :
42+ raise ValueError (f"Could not get API Gateway URL from Parameter Store: { e } " )
3543
3644 print (f"Starting approval workflow for request: { request_id } " )
3745 print (f"API Base URL: { api_base_url } " )
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ Resources:
6868 Variables :
6969 APPROVAL_TOPIC_ARN : !Ref ApprovalTopic
7070 CALLBACK_TABLE_NAME : !Ref CallbackTable
71- API_BASE_URL : !Sub 'https://${ApprovalApi}.execute-api.${ AWS::Region}.amazonaws.com/prod '
71+ API_GATEWAY_PARAM : !Sub '/${ AWS::StackName}/api-gateway-url '
7272 Policies :
7373 - SNSPublishMessagePolicy :
7474 TopicName : !GetAtt ApprovalTopic.TopicName
@@ -79,6 +79,10 @@ Resources:
7979 Action :
8080 - lambda:CheckpointDurableExecution
8181 Resource : !Sub 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${AWS::StackName}-ApprovalFunction-*'
82+ - Effect : Allow
83+ Action :
84+ - ssm:GetParameter
85+ Resource : !Sub 'arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${AWS::StackName}/api-gateway-url'
8286
8387 # IAM Role for API Gateway to call Lambda service API
8488 ApiGatewayRole :
@@ -167,6 +171,16 @@ Resources:
167171 uri : !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${CallbackHandlerFunction.Arn}/invocations'
168172 passthroughBehavior : when_no_match
169173
174+ # Store API Gateway URL in Parameter Store
175+ ApiGatewayUrlParameter :
176+ Type : AWS::SSM::Parameter
177+ Properties :
178+ Name : !Sub '/${AWS::StackName}/api-gateway-url'
179+ Type : String
180+ Value : !Sub 'https://${ApprovalApi}.execute-api.${AWS::Region}.amazonaws.com/prod'
181+ Description : ' API Gateway URL for the approval workflow'
182+ DependsOn : ApprovalApi
183+
170184Outputs :
171185 ApiEndpoint :
172186 Description : API Gateway endpoint URL
You can’t perform that action at this time.
0 commit comments