Exposing Functions with Function URLs and Response Streaming
This lesson explains how to call a function directly over HTTPS. A function URL gives a single function its own HTTPS endpoint without API Gateway, and response streaming lets the function send its response in parts as it is produced.
Learning outcomes
After completing this lesson, you will be able to:
- Compare function URLs with API Gateway and choose the right option for an HTTP endpoint.
- Describe the authentication and cross-origin resource sharing (CORS) options of a function URL.
- Explain when response streaming improves time to first byte and how it avoids the 6 MB limit on buffered responses.
Function URLs vs API Gateway
A function URL gives a single function its own HTTPS endpoint at no extra cost. It supports two authentication types: AWS_IAM, which requires callers to sign requests with Signature Version 4, and NONE, which makes the URL public so the function must check any credentials itself. CORS can be configured on the URL, and a URL can stream its response. Because a function URL invokes the function directly, the request can run for the function's full timeout of up to 15 minutes.
A function URL has no API management features. It cannot validate requests, cache responses, enforce per-client quotas or use AWS WAF directly, and the only way to limit its request rate is the function's reserved concurrency. API Gateway provides these features, together with Cognito, JWT and Lambda authorizers, and can route many paths to many backends. A function URL therefore suits a webhook or a simple endpoint for a single function, whereas a public API with several operations and external clients normally needs API Gateway.
The following table compares the two options.
AWS_IAM or NONE (public)Example. A function URL that only signed IAM requests from callers with lambda:InvokeFunctionUrl and lambda:InvokeFunction can use:
aws lambda create-function-url-config --function-name report-webhook \
--qualifier live --auth-type AWS_IAM \
--cors '{"AllowOrigins":["https://app.example.com"],"AllowMethods":["POST"]}'Function URL details
A function URL provides a dedicated HTTPS endpoint for a Lambda function. The following list describes its format, authentication and behaviour.
- The URL has the form
https://<url-id>.lambda-url.<region>.on.awsand can point at$LATESTor an alias, but not a numbered version. - With
AuthType NONEthe URL is public, but the function's resource-based policy must still allow all principals to calllambda:InvokeFunctionUrland, for URLs created since October 2025,lambda:InvokeFunction; a missing grant returns 403 Forbidden. - The function receives an event in the same format as an API Gateway HTTP API (payload format version 2.0).
- A custom domain or AWS WAF requires placing CloudFront in front of the URL.
Response streaming
Response streaming sends the response in parts as it is produced, through function URLs with the RESPONSE_STREAM invoke mode or through the InvokeWithResponseStream API. It improves time to first byte for large responses and generative AI output, and allows responses larger than the 6 MB limit of buffered responses.
Node.js supports streaming natively with the awslambda.streamifyResponse() wrapper; other languages use a custom runtime or the Lambda Web Adapter.
export const handler = awslambda.streamifyResponse(async (event, responseStream) => {
for await (const chunk of generateReport()) {
responseStream.write(chunk); // each chunk reaches the client as soon as it is written
}
responseStream.end();
});Function URL or API Gateway?
A Lambda function may be exposed through a function URL or through API Gateway. The following table identifies the appropriate choice for several requirements and the reason in each case.
| Requirement | Choice | Why |
|---|---|---|
| A webhook endpoint for one partner, with no API features needed | Function URL with IAM or a shared secret check | Simplest and free; one HTTPS endpoint |
| A public API with usage plans, API keys and request validation | API Gateway REST API | Function URLs have no throttling per client, no validation, no keys |
| Streaming a large AI-generated response to the browser | Function URL with response streaming | Sends bytes as they are produced |
| Custom domain with WAF in front | API Gateway, or CloudFront in front of a function URL | Function URLs have no native custom domain or WAF |
Whichever entry point is used, the same best practices apply inside the function: initialise SDK clients outside the handler, keep the package small, read configuration from environment variables or Parameter Store, and use an extension such as the Parameters and Secrets extension to cache values instead of calling the API on every invocation.
A team needs a public HTTPS endpoint for one function, with API keys and request quotas for each client. Is a function URL enough?
Show answer
No. A function URL supports IAM authentication or no authentication, but it has no usage plans or API keys. An API Gateway REST API provides per-client throttling and quotas through usage plans.
Exam Tips
Remember for the exam
- A simple HTTPS endpoint for one function is a function URL; API keys, per-client throttling or WAF require API Gateway.
- Large or incremental responses call for Lambda response streaming.
- A function URL can target
$LATESTor an alias, not a numbered version. - A custom domain or WAF in front of a function URL requires CloudFront.