Home > Blockchain >  Performance and Cost Comparison of Lambda@Edge vs Lambda as Cloudfront Origin
Performance and Cost Comparison of Lambda@Edge vs Lambda as Cloudfront Origin

Time:06-03

I'm creating a service where a client needs to get some data stored in a DynamoDB table. I'm using Cloudfront as a CDN for reducing latency. I have 2 methods of obtaining the data from the DynamoDB table.

Method 1: The client sends a request to Cloudfront. Cloudfront checks for a cached response. Assuming a cached response is not available, Cloudfront invokes a Lambda@Edge function with an Origin Request trigger. The Lambda@Edge function queries the DynamoDB table, gets the data and sends it to the Cloudfront edge location. Cloudfront caches the response from the Lambda@Edge function and responds to the client. Question: what should the Cloudfront origin be set in this case?

Method 2: Client sends a request to Cloudfront. Cloudfront checks for cached response. Assuming a cached response is not available, Cloudfront forwards the request to the origin, which in this case will be a Lambda function. The Lambda receives the Cloudfront request and queries the DynamoDB table, gets the data and sends it back to the Cloudfront distribution. Cloudfront edge server caches the response, and forwards it to the client.

Which method would be better in terms of latency, and in terms of cost. Also is there a better way to solve this problem?

CodePudding user response:

Method 1 - just set a S3 bucket as an origin, (you need to set something), and make sure you return from the origin request edge lambda every time (and it would never reach the S3)

I don't think there is a significant difference between pricing or performance! Most of your call would be cached I assume. In the long term I would say it would be almost the same, if you have a good cache hit ratio!

  • Related