When to use API Gateway vs. Lambda Function URLsRead on my blog Read time: 4 minutes “Lambdalith” is a monolithic approach to building serverless applications where a single Lambda function serves an entire API, instead of one function per endpoint. It’s an increasingly popular approach. It provides portability between Lambda functions and container applications. You can lift and shift an existing application into Lambda without rewriting it. You can use web frameworks you are already familiar with, and lean on the existing ecosystems of tools, ORMs and middleware. It also makes testing easier, because you can apply familiar testing methodologies. Tools like the AWS Lambda Web Adapter [1] have made this approach more accessible. In addition, Lambda Function URLs [2] also work well with this pattern. Which brings up a good question. “In 2024, if you want to build a REST API using serverless technologies. Should you use Lambda Function URLs or API Gateway?” Here are some trade-offs you should consider when making this decision. Function URL pros
Function URL cons
Where Function URL makes senseIf you want to (i.e. not forced into it by the choice to use Function URL) build a Lambdalith and you don’t need any of the additional features that API Gateway offers. Then Function URLs make sense — it’s cheaper, faster and has fewer moving parts. Similarly, if you need to return a large payload (> 10MB) or to run for more than 29s, then Function URL can also make sense. That is if you can’t refactor the client-server interaction. Given the limited support for authentication & authorization, it’s not suitable for user-facing APIs. These APIs often require a Cognito authorizer or a custom Lambda authorizer. This leaves function URLs as best suited for public APIs or internal APIs inside a microservices architecture. By “internal API”, I refer to APIs that are used by other services but not by the frontend application directly. These APIs usually require AWS_IAM auth because the caller is another AWS resource — a Lambda function, an EC2 instance, an ECS task, etc. API Gateway pros
API Gateway cons
When API Gateway makes senseGiven the vast array of features that API Gateway offers, it makes sense in most cases if you’re OK with the additional cost that comes with the convenience. The 29s and 10MB response limits can be problematic in some cases. But they can be mitigated with patterns such as Decoupled Invocations [6] and S3 presigned URLs [7]. However, these workarounds require you to refactor the client-server interaction, so they are not always viable. SummaryBecause of its flexibility, I prefer API Gateway over Function URLs or ALBs. But Function URL is a useful tool, especially when cost and performance are your primary concerns. It’s also an important lift-and-shift option for people migrating from an existing EC2 or container-based application. It lets them enjoy the benefits of Lambda without rewriting their application. Finally, as Ben eloquently puts it, this tradeoff represents a deeper choice we often face. What’s easier at author time might mean more ownership at runtime. For example, we don’t get per-endpoint metrics from function URLs so we have to bring that capability to the table ourselves and be responsible for them. Something for you to think about ;-) Links[2] AWS Lambda: function URL is live! [3] Introducing AWS Lambda response streaming [4] Embedded metric format specification [5] API Gateway: Why you should use Service Proxies [6] How to use the Decoupled Invocation pattern with AWS Lambda and serverless [7] Hit the 6MB Lambda payload limit? Here’s what you can do Whenever you're ready, here are 3 ways I can help you:
|
Join 17K readers and level up you AWS game with just 5 mins a week.
Modern applications rarely do just one thing at a time. An API request creates an order, and then another service needs to reserve stock, another to charge the customer, another to send an email, and so on. In a serverless or event-driven architecture, follow-up actions are usually triggered by messages (either events or commands). That gives us loose coupling, better scalability, and independent services. But it also introduces a reliability problem. “What happens when the database update...
If you use Claude Code a lot, you’ve probably run into usage limits, sometimes even in short coding sessions. But cost isn’t the only problem. In long-running sessions, the context window eventually fills up, and that can cause the agent to forget earlier decisions, lose important details, or come back from compaction with gaps in its working memory. Here are three tools worth checking out if you want to reduce token usage and make longer coding sessions possible. 1. CavemanThis is a Claude...
AI agents can now scan an entire open-source codebase for exploitable vulnerabilities in hours. Frontier models carry the complete library of known bug classes in their weights. So you can simply point an AI agent at a codebase and tell it to find zero-days. This isn't theoretical. Willy Tarreau, the HAProxy lead developer, reports that security bug reports have jumped from 2–3 per week to 5–10 per day. Greg Kroah-Hartman, the Linux kernel maintainer, described what happened: "Months ago, we...