简体   繁体   中英

AWS Lambda chaining best practice

I'm looking a solution for my problem and maybe someone could give me some ideas. I have a API Gateway plugged to a aws lambda A. I have to handle cases like this:

  1. Lambda A should call lambda B and if there are any results, return to the API Gateway.
  2. Lambda A should call lambda B and if no results, it will call lambda C, and then return whatever the results are to the APi Gateway .

So, my problem is how to chain these lambdas, because I don't want to have a huge lambda. At first, I thought about using Step Functions except that this works in a asynchronous mode, so no good for my case. I know I can do a lambda to call the step function and wait for the result, but I don't like this solution.

Any ideas for a nice solution ?

Thanks.

CC

您可以使用AWS Step Function管理 AWS lambda 函数之间的协调。

Really B & C are apis that A is calling

Put lambda B & C behind another api gateway, using IAM auth. Give A rights to call that Api via your IAM Role.

  • Now Your external clients call A via whatever auth scheme.
  • A is free to call B or C via api (url as parameter perhaps)
  • A can return results to caller

For a more granular approach, you can have B/C as their own api gateways, meaning your have decoupled them fully

MiniEdit: For something like this I'd also consider using the Lambda Function URLs now: https://docs.aws.amazon.com/lambda/latest/dg/lambda-urls.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM