简体   繁体   中英

Why do we need Lambda in between API Gateway and Dynamo DB in AWS?

I am building a service using AWS. My use case is a simple CRUD operation, of a product configuration, on Dynamo DB using API's.

Approach 1: I was initially thinking to design it using API Gateway, Lambda and DynamoDB.

Approach 2: One of my peers asked me to directly integrate API Gateway with DynamoDB.

In my understanding, as of now, using Lambda as a middle layer will help me better to deliver customized responses and also would do some extra error validation (like bad keys supplied by user) in addition to API Gateway. But I am still not very much convinced to go by approach 1 or 2.

I was wondering if anyone could help me elaborate some pros and cons of approach 2 in relation to approach 1. Any help would be much appreciated.

My product configuration is a bunch of 15 key value pairs.

I was wondering if anyone could help me elaborate some pros and cons of approach 2 in relation to approach 1.

There could be several pros and cons . Example of a positive is that you pay only for API Gateway and DynamoDb - not for lambda invocations. Example of a negative is is that an initial setup and maintainability of API->DynamoDB can be more complex and tiresome then when using API->Lambda->DynamoDb.

However, one drawback of the first approach that can be important in may use cases is time efficiency. Lambda function is known to suffer from so called, cold start latency (more and how to deal with this is here - Provisioned Concurrency). Subsequently, in Approach 1 with lambda, you may find that the cold start is a troublesome, especially for in-frequently used APIs. In contrast, in the Approach 2, you have direct connection between API and DynamoDB and don't have to worry about any delays caused by intermediates between API gateway and DynamoDB.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM