Use NodeJS Lambda Destination to send JSON to NodeJS Lambda within VPC

0

I have a Lambda in NodeJS 18 which is accessible by Function URL. Depending on request GET parameters it outputs different JSON data to the web browser. Instead of this behavior, I want to have my output go to another Lambda function that writes to an EFS within a VPC. How can I test this and what variables does the first Lambda function output that the second reads from asynchronously?

I know how to write to the EFS, I just don't know how to get the data from the first lambda function into some kind of readable stream that the second Lambda can read.

Bryan C
gefragt vor einem Jahr669 Aufrufe
2 Antworten
0

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:

  1. Go to the lambda function B.
  2. Click on Configuration tab.
  3. Click on Permissions Option.
  4. On Resource-based policy statements tab, choose to add permisssions.
  5. 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
  6. Save the permissions.

[+] Using resource-based policies for Lambda - https://docs.aws.amazon.com/lambda/latest/dg/access-control-resource-based.html

AWS
SUPPORT-TECHNIKER
beantwortet vor einem Jahr
profile picture
EXPERTE
überprüft vor einem Monat
0

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:

  1. Invoke function B from function A. Use the asynchronous invocation mode so that function A does not wait for function B to complete.
  2. 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.
profile pictureAWS
EXPERTE
Uri
beantwortet vor einem Jahr
profile picture
EXPERTE
überprüft vor einem Monat

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen