Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoking AWS Lambda - API Gateway vs direct invocation

We are a team of 10 developers, trying to move process intensive jobs from our Rails application on Heroku to AWS Lambda (Java). We are blocked on deciding whether to invoke lambda functions via API gateway or via AWS Ruby SDK directly. Depending on the use case, we might have to invoke lambda asynchronously as well. Our payload is very small (< 1-2 KB). We are considering direct invocation primarily to maximise execution time. We are looking for pointers here:

  1. Is it easy(& faster) for API gateway to verify the IAM role required to invoke lambda ?
  2. Is there any significant reduction in latency b/w lambda and API gateway?
like image 460
viveksura Avatar asked Jun 11 '26 01:06

viveksura


2 Answers

As others have stated, adding API Gateway does not improve performance but does add extra overhead. Use API Gateway if any of the additional feature it provides are useful to you. If you control the client, can get credentials on the client with permissions to invoke your Lambda functions directly, and don't need/want any of the additional API Gateway features, the go with the Lambda direct invoke.

like image 164
MikeD at AWS Avatar answered Jun 13 '26 17:06

MikeD at AWS


Direct lambda calls are faster b/c there's one network hop less. I doubt you can directly compare lambdas/APIG with regard to latency of IAM verification, but we've benchmarked lambda-lambda calls and lambda-APIG-lambda calls, where the lambdas do no work, i.e. simply return the event object. The average timings are as follows:

  • lambda-lambda: 27ms

  • lambda-APIG: 47ms

So the tax for the extra hop is 20 ms. We use lambda-lambda calls whenever feasible, especially with lambdas we don't want to expose to the world.

like image 37
olyN Avatar answered Jun 13 '26 19:06

olyN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!