AWS Lambda Function URLs vs. Amazon API Gateway

April 8, 2022

Introduction

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:

https://{restapi_id}.execute-api.{region}.amazonaws.com/{stage_name}/

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

Click here for link to: API Gateway payload format 2.0

Serverless Framework IaC - AWS Lambda Function URLs

  
$ serverless deploy

Deploying sls-lambda-function-url to stage dev (ap-south-1)

✔ Service deployed to stack sls-lambda-function-url-dev (56s)

endpoint: GET - https://XXXXXXXXXX.execute-api.ap-south-1.amazonaws.com/dev/lambda-api-gateway-api
functions:
  lambdaAPIGatewayAPI: sls-lambda-function-url-dev-lambdaAPIGatewayAPI (392 B)
  

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

  
$ serverless deploy

Deploying sls-lambda-function-url to stage dev (ap-south-1)

✔ Service deployed to stack sls-lambda-function-url-dev (56s)

endpoint: GET - https://XXXXXXXXXX.execute-api.ap-south-1.amazonaws.com/dev/lambda-api-gateway-api
functions:
  lambdaAPIGatewayAPI: sls-lambda-function-url-dev-lambdaAPIGatewayAPI (392 B)
  

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.

Conclusion

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.

Sources

  1. https://aws.amazon.com/blogs/aws/announcing-aws-lambda-function-urls-built-in-https-endpoints-for-single-function-microservices/
  2. https://www.serverless.com/blog/aws-lambda-function-urls-with-serverless-framework
  3. https://lumigo.io/blog/aws-lambda-function-url-is-live/
Serverless Handbook
Access free book

The dream team

At Serverless Guru, we're a collective of proactive solution finders. We prioritize genuineness, forward-thinking vision, and above all, we commit to diligently serving our members each and every day.

See open positions

Looking for skilled architects & developers?

Join businesses around the globe that trust our services. Let's start your serverless journey. Get in touch today!
Ryan Jones - Founder
Ryan Jones
Founder
Speak to a Guru
arrow
Edu Marcos - CTO
Edu Marcos
Chief Technology Officer
Speak to a Guru
arrow
Mason Toberny
Mason Toberny
Head of Enterprise Accounts
Speak to a Guru
arrow

Join the Community

Gather, share, and learn about AWS and serverless with enthusiasts worldwide in our open and free community.