Invoking AWS Lambda API Gateway vs Direct Invocation

+1 vote
Hi there,

I and my team are trying to move process intensive jobs from our Rails application on Heroku to AWS Lambda (Java). We are stuck 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 maximize the execution time. We are looking for the points mentioned below:
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?

Thanks in Advance for the answer :)
Apr 17, 2018 in AWS by Cloud gunner
• 4,260 points
512 views

2 answers to this question.

+1 vote
Best answer
Most of the time, adding API Gateway does not improve the performance but does add an extra overhead, use API Gateway if any of the additional features it provides are useful to you. If you control the client then can get credentials on the client with permissions to invoke your Lambda functions directly, and you don't want any of the additional API Gateway features then go with the Lambda direct invoke.
Either way, direct lambda calls are faster bcz there's one network hop-less. Maybe you can directly compare lambdas/APIG with regard to the latency of your 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 time usually is taken, I am mentioning below:

•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.
Let me know if you and your team's able to complete this task, will be happy to help more :)
answered Apr 17, 2018 by Flying geek
• 3,150 points

selected Aug 23, 2018 by Priyaj
0 votes

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.

answered Aug 3, 2018 by Priyaj
• 56,160 points

Related Questions In AWS

0 votes
2 answers
+1 vote
3 answers

Not able to pass params POST to AWS Lambda from Amazon API Gateway

For this template : application/x-www-form-urlencoded  This line below will ...READ MORE

answered Jun 13, 2018 in AWS by Cloud gunner
• 4,260 points
1,676 views
0 votes
1 answer
0 votes
1 answer
+1 vote
3 answers

Which is better ? AWS S3 bucket logs vs AWS cloudtrail

CloudTrail logs API calls accessed to your ...READ MORE

answered Aug 16, 2018 in AWS by Priyaj
• 56,160 points
1,628 views
+5 votes
13 answers

AWS VPC - What is the difference between Internet Gateway & NAT

Internet Gateway An Internet Gateway is a logical connection ...READ MORE

answered Apr 24, 2018 in AWS by Flying geek
• 3,150 points
7,313 views