5

Serving APIs from Lambda@Edge offers more latency benefit than serving APIs from API-Gateway + Lambda stack, if my understanding is correct.

Plus, cost of API-Gateway ($3.5/million call) + Lambda ($0.2/million call) == $3.7 / million call seems to be more expensive than Lambda@Edge ($0.6 / million call).

If both of the above observations are true, shouldn't we all migrate our API-Gateway + Lambda (for those who use this stack) to lambda@edge stack?

Chris Williams
  • 32,215
  • 4
  • 30
  • 68
chen
  • 4,302
  • 6
  • 41
  • 70
  • CloudFront costs you $1/million so total price with Lambda@edge would be $1.6/million so Api Gateway can be cheaper if you use HTTP API. – CodesInTheDark Jan 01 '22 at 04:08

2 Answers2

2

Lambda@Edge is primarily event driven for requests, yes the latency is reduced but it is designed to be used with an origin. Even if you have the Lambda@Edge function your CloudFront distribution would still need to reach out to the origin.

When the origin is an API Gateway (with or without a Lambda) there are so many benefits come with it such as:

  • Built in support for OpenAPI spec
  • Built in routing
  • Support for canary deployments
  • Authentication and authorization built in, with support for throttling per API user
  • Built in support for model schema validation
  • Support to manage your API as Infrastructure as Code: CloudFormation, Terraform, SAM
  • Each request can be developed separately, you can only have 1 Lambda@Edge function per event so you might see collisions in a team (not to mention very large functions).

If this was all needed to be done by Lambda@Edge then you would need to design, develop and maintain these features.

The price you refer to is for REST API, bare in mind there 3 kinds of API the cheapest is HTTP API which costs $1.00 per million requests.

Chris Williams
  • 32,215
  • 4
  • 30
  • 68
2

Lambda@Edge has many limitations as compared to regular lambda. For examples:

  • its only for node.js and python,
  • no lambda layers!
  • no AWS X-Ray!
  • max timeout 30 seconds,
  • and many more.

Thus, it would be difficult in many cases to migrate to Lambda@Edge and to give up all these benefits of regular lambda.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • Do you know how to do the reverse migration i.e. from lambda@edge to regular lambda? Do you know of a guide/doc that explains the necessary steps? I'm still learning my way around aws to bear with me pls. – Uche Ozoemena Jan 14 '22 at 12:32