Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

amazon web services - What is the best way to internally call an AWS Lambda function within another Lambda function?

Seems a little inefficient the way it currently is:

response.body = {
   user: await userService(userID) // calls a user service to get info on user
   friends: await friendsService(userID) // calls a friends service to get info on friends for 
}

Let's say the userService and friendsService are configured on different API Gateway endpoints.

Then wouldn't that make the network request take longer than if I were to just package my entire backend into one zip file that's uploaded to AWS Lambda.

Seems like this is very inefficient.

Is there a way to call other lambdas without having to make a network request? I understand putting the lambdas/gateway in the same VPC as the main Gateway endpoint exposed to the internet, but this is expensive?

Anyway to do this more efficiently?

question from:https://stackoverflow.com/questions/65906702/what-is-the-best-way-to-internally-call-an-aws-lambda-function-within-another-la

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can call a Lambda function by using the AWS SDK (a LambdaClient object). So, for example assume you wrote two Lambda functions - funA and funB.

Next assume:

  • you want to call funB from funA
  • you wrote your Lambda function by using the Lambda Java runtime

You can use the Lambda Java API to invoke funB. There is no need to wrap either one in Restful call using API Gateway. You can use the AWS SDK. Here is the Java API example that shows you how to invoke a Lambda function:

https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javav2/example_code/lambda/src/main/java/com/example/lambda/LambdaInvoke.java


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...