Every Lambda that serves HTTP needs a front door. For years that meant API Gateway by default. Function URLs now give each function a built-in HTTPS endpoint at no extra charge, and they are a good fit for more workloads than teams assume. This guide shows how to choose, and how to configure both with Serverless Framework V4.
What a Function URL gives you
A Function URL is a dedicated endpoint (https://<id>.lambda-url.<region>.on.aws) mapped to one function. It supports two auth modes (NONE and AWS_IAM), CORS settings, and optional response streaming. It has no built-in usage plans, API keys, request validation, throttling per client, WAF attachment, or custom domains.
Decision table
| Need | Function URL | API Gateway HTTP API | API Gateway REST API |
|---|---|---|---|
| Single webhook receiver | Best fit | Fine | Overkill |
| Many routes, one service | Possible (router in code) | Best fit | Fine |
| JWT authorizer built in | No (verify in code) | Yes | Cognito/Lambda authorizers |
| Usage plans and API keys | No | No | Yes |
| WAF directly attached | No (use CloudFront) | No | Yes |
| Custom domain | Via CloudFront | Native | Native |
| Extra per-request cost | None | Per million requests | Higher per million |
Rule of thumb: use a Function URL for webhooks, internal service-to-service calls with IAM auth, and streaming endpoints. Use API Gateway when you need per-route auth, throttling per consumer, or request validation.
Configuring a Function URL in serverless.yml
service: webhook-receiver
frameworkVersion: '4'
provider:
name: aws
runtime: nodejs22.x
region: us-east-1
functions:
receive:
handler: src/receive.handler
url:
authorizer: aws_iam
cors:
allowedOrigins:
- https://app.example.com
allowedMethods:
- POST
allowedHeaders:
- content-type
- x-signature
maxAge: 3600
Omit authorizer (or leave the default) for a public endpoint. A public URL must authenticate callers itself, so verify an HMAC signature on every request:
import { createHmac, timingSafeEqual } from 'node:crypto';
export const handler = async (event) => {
const expected = createHmac('sha256', process.env.WEBHOOK_SECRET)
.update(event.body ?? '')
.digest('hex');
const given = event.headers['x-signature'] ?? '';
const ok = given.length === expected.length &&
timingSafeEqual(Buffer.from(given), Buffer.from(expected));
if (!ok) return { statusCode: 401, body: 'invalid signature' };
// enqueue work, return quickly
return { statusCode: 202, body: 'accepted' };
};
Return fast and hand real work to SQS or EventBridge so a slow downstream does not cause sender retries.
Calling an IAM-protected URL
Callers must sign requests with SigV4 for the lambda service. The caller's role needs lambda:InvokeFunctionUrl on the function:
resources:
Resources:
CallerPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: lambda:InvokeFunctionUrl
Resource: !GetAtt ReceiveLambdaFunction.Arn
Condition:
StringEquals:
lambda:FunctionUrlAuthType: AWS_IAM
Verify the exact resource logical ID with serverless package and inspect the generated template, since naming follows the function key.
Putting CloudFront in front
To get a custom domain, WAF, and caching, put a CloudFront distribution in front of the URL. If you keep the URL IAM-protected, use origin access control for Lambda so CloudFront signs requests. If you cannot, keep the URL public but require a secret header that CloudFront injects and your code checks. See our post on custom domains and CloudFront for the distribution setup.
Exposing the URL as a stack output
resources:
Outputs:
ReceiveUrl:
Value: !GetAtt ReceiveLambdaFunctionUrl.FunctionUrl
Other services can then consume it through Serverless Framework Compose shared outputs.
Migrating from API Gateway
- Deploy the Function URL alongside the existing
httpApievent; both can point at the same function. - Normalize the event shape. Function URLs use the payload format 2.0 structure, the same as HTTP APIs, so handlers written for HTTP APIs usually work unchanged.
- Move auth: replace the API Gateway authorizer with IAM auth or in-code verification.
- Shift traffic by DNS or CloudFront weights, watch 4xx/5xx rates, then remove the
httpApievent.
Pitfalls we see in reviews
- Public URL with no verification. Anyone who finds the URL can invoke the function and run up cost. Set reserved concurrency as a ceiling.
- CORS handled twice. If both the URL config and your code emit CORS headers, browsers see duplicates and reject the response. Pick one.
- No throttling story. Without API Gateway, use reserved concurrency and a WAF at CloudFront to limit abuse.
- Routing sprawl. Once a function URL hosts more than a handful of routes with a router library, API Gateway usually becomes simpler to operate.
Summary
Function URLs remove a layer for simple endpoints and cost nothing extra, while API Gateway still wins on consumer management and per-route controls. Choose per service, not per company, and keep the choice reversible by sharing the HTTP API payload format.
Need help choosing or migrating your API entry points? Get in touch and our serverless consultants will review your architecture.