viveksura
viveksura

Reputation: 155

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?

Upvotes: 8

Views: 5760

Answers (2)

MikeD at AWS
MikeD at AWS

Reputation: 3745

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.

Upvotes: 9

olyN
olyN

Reputation: 181

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.

Upvotes: 8

Related Questions