Skip to content

Replace API Gateway with CloudFront + Lambda Function URLs everywhere in Bref? #1625

@mnapoli

Description

@mnapoli

Right now, Bref's docs/examples/defaults deploy:

graph LR;
API(API Gateway)-->Lambda(Lambda);
Loading

For websites, it deploys:

graph LR;
CloudFront-->API(API Gateway)
API-->Lambda(Lambda);
Loading

Lambda Function URLs are great to replace API Gateway. However they don't have custom domains. That means you need CloudFront (for the custom domain). That works for websites right now (we already have CloudFront there), but not APIs (which don't use CloudFront).

How about dropping API Gateway entirely (for the docs/examples, Bref would still work with it of course) and go full Lambda Function URLs + CloudFront.

We would have 3 different scenarios:

  • No custom domain: Lambda Function URL
    That would be super cheap for testing and deploying preview URLs.
  • Website: CloudFront -> Lambda Function URL
    Same as today, no changes except API Gateway is removed.
  • API: CloudFront -> Lambda Function URL
graph LR;
CloudFront-->Lambda(Lambda Function URL);
Loading

Pros:

  • Slightly simpler serverless.yml config
  • Websites would be cheaper to host (no API Gateway)
  • Possibly slightly faster first deployments (no API Gateway to setup/deploy)
  • Slightly less HTTP latency as Function URLs are slightly faster than API Gateway
  • Simpler infrastructure, always the same regardless of the use case
  • CloudFront takes care of redirecting HTTP -> HTTPS (API Gateway doesn't), that's a win!
  • Longer HTTP timeouts!

Cons:

  • Longer deployment time when you want a custom domain on an API (for websites we already deploy CloudFront, so it wouldn't be slower)
  • The Lambda Function URL would be publicly (on top of the CloudFront URL), making it private would require some more effort (custom header or using Lambda@Edge)
  • Cannot use API Gateway features: that would still be possible, but be advanced, which makes sense to me. We don't use API Gateway features in Bref docs.
  • Is CloudFront more expensive than API Gateway for APIs?
    I did rough calculations and it seems that it could be actually cheaper for 99% of use cases! CloudFront has a much bigger free tier (10 million HTTP requests, compared to 1 million for API Gateway). Beyond that, it seems to be about the same price, but even at this scale it can be optimized on a case by case basis.

Summary:

Running APIs and websites might be simpler, faster and cheaper!

Am I missing anything? Feedback is welcome 🙏

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions