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:
- Lambda A should call lambda B and if there are any results, return to the API Gateway.
- 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.
C.C.
You can use invoke lambda with "async await" here is docs:
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#invoke-property
For asynchronous call: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#invokeAsync-property
You can use AWS Step Function to manage coordination between AWS lambda functions.
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
来源:https://stackoverflow.com/questions/49014212/aws-lambda-chaining-best-practice