- Newest
- Most votes
- Most comments
As per the description, I understand that the flow of the request is as follows:
Function URL → Lambda A → Lambda B → EFS
Depending on the HTTP method of the request from function URL, Lambda A returns response to the client. But now you want to send the response to Lambda B from Lambda A i.e. basically make Lambda A to invoke Lambda B.
To invoke a Lambda function you can use Lambda:InvokeFucntion action in code of Lambda A and send the payload to Lambda B, which will be received by Lambda B as an event. And in Lambda B sort the required details from the event payload and write it to EFS.
[+] Invoke - https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html [+] https://docs.aws.amazon.com/goto/AWSJavaScriptSDK/lambda-2015-03-31/Invoke
To invoke Lambda B, Lambda B should have Lambda:InvokeFunction resource based policy which will allow the Lambda A to invoke Lambda B.
Following are the steps to add resource based policy to Lambda B:
- Go to the lambda function B.
- Click on Configuration tab.
- Click on Permissions Option.
- On Resource-based policy statements tab, choose to add permisssions.
- Select AWS Service and provide the following values:
Service: Other
StatementID: Enter a unique statement ID
Principal: lambda.amazonaws.com
Source Arn: <Paste the ARN of Lambda A> Action: Lambda:InvokeFunction - Save the permissions.
[+] Using resource-based policies for Lambda - https://docs.aws.amazon.com/lambda/latest/dg/access-control-resource-based.html
Lambda has a feature called Lambda Destinations which sends the result of a function to some other destination (SNS, SQS, EventBridge or a different function). This feature however, only works for asynchronous invocations, which is not the case when invoked using Lambda Function URLs.
You have several options:
- Invoke function B from function A. Use the asynchronous invocation mode so that function A does not wait for function B to complete.
- Instead of using function URL, use API gateway to invoke an Express Step Functions state machine synchronously. The state machine will invoke function A and with when done, it will invoke function B asynchronously and return the result to API gateway, which will return to the client.
Relevant content
- asked 2 years ago
- asked 2 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago