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,670 points
5,273 views

3 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,280 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
• 58,020 points
0 votes

Over the 4 years I implementing Client + AWS SDK on my serverless approach. Direct hit to all microservices we have such as Lambda, DynamoDB, S3, SQS, etc.

To work with this approach, we have to strong understand about IAM Role Policy including its statements concept, Authentication Token, AWS Credential, and Token - Credential exchange.

For me, using SDK is better to implement serverless rather than API Gateway. Why I prefer to implementing SDK instead of API on my serverless infra?

  • API Gateway is Costly
  • Network hop-less
  • In fact, SDK is commonly contain an API to communicate with other applications Class base and simple call such as dynamodb.put(params).promise(), lambda.invoke(params).promise(), s3.putObject(params).promise(), etc. We can see a sample API call like fetch(URL).promise(), the term is not really different
  • API is more complex and some case can't or shouldn't be handled with
  • SDK is not scalable? No, I dont think so. Because it's class base, it's so scalable.
  • Slimming the infra and code writing, i.e to work with s3 no need deploy API+Lambda
  • Speed up the process, i.e storing data to dynamodb no need business logic through API+lambda
  • Easy maintaining, we only maintain our client code
  • Role Policy is more scalable; etc
answered Feb 28, 2020 by Mahdi

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,670 points
8,748 views
0 votes
1 answer
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
• 58,020 points
7,381 views
+9 votes
17 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,280 points

edited Jul 10, 2023 by Khan Sarfaraz 128,508 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP