Looking for Senior AWS Serverless Architects & Engineers?Let's Talk
In this article, we will look at the differences between AWS Lambda Function URLs and Amazon API Gateway to help you decide when to use one over the other. You can access this article's FREE template for download HERE.
What is AWS Lambda Function URL?
AWS Lambda Function URL is used to assign HTTPS endpoints to your Lambda function, AWS Function URLs is a recently launched feature for AWS Lambda on Apr 6, 2022, that allows calling Lambda function directly using function URLs.
Lambda Console / Lambda API allows you to create and configure a Function URL; AWS Lambda Function URL have this format: https://<url-id>.lambda-url.<region>.on.aws
For new or existing Lambda functions it is possible to add Function URLs.Here is how to add Function URLs during creating a new Lambda function in AWS Console:
- Lambda → Functions → Create function → Advanced settings → Enable function URL
Lambda Function URL Supports:
- Auth Type: AWS_IAM | NONE
- Configure CORS
What is Amazon API Gateway?
Amazon API Gateway is an AWS service for creating REST, HTTP, and WebSocket APIs at any scale. API Gateway acts as the HTTPS endpoint URL when Amazon API Gateway, along with AWS Lambda, is used to build APIs.
Amazon API Gateway endpoints have this format:
Amazon API Gateway can be used for the cases which require advanced authorization using Cognito, Throttling, Caching, Service proxy to other AWS services, Usage plans, WebSockets, Request/Response mapping/validation, and more such advanced features.
Differences Between AWS Lambda Function URLs & Amazon API Gateway
Serverless Framework IaC - AWS Lambda Function URLs
Relevant Note: AWS Lambda Function URL features are only supported by Serverless Framework v3.12.0 (or greater versions).
Above, the IaC deployed ‘lambdaFunctionURLAPI’ Lambda with the Function URL Configuration you can find below.
Serverless Framework IaC - Amazon API Gateway + AWS Lambda
Above, the IaC deployed ‘lambdaAPIGatewayAPI’ Lambda with API Gateway set as Trigger. Also, you can notice in this screenshot that the Function URL is not set for this lambda.
In this article you've been given an initial idea about AWS Lambda Function URLs so that you are able to explore it and use it in production scenarios later.
AWS Lambda Function URLs should work well for use cases like APIs built with backend frameworks, webhooks, form validators, server-side website rendering, long-polling scenarios, single-function simple microservice, and other relevant cases.
Amazon API Gateway should work well for advanced use cases like SaaS applications that need to track limit usage using API Gateway Usage Plans, real-time applications using WebSockets, cases where API response time is within 29 seconds, cases that require advanced authorization using Cognito, Throttling, Caching, Service Proxy to other AWS services, and more.