AWS Lambda Function URLs — A beginner’s guide

Abhinav Singh
3 min readApr 7, 2022

--

AWS has recently launched Lambda Function URLs, a brand new feature which allows you to map a built-in HTTPS endpoint to any of your Lambda function.
It allows you to configure the CORS, Authorization, Allowed HTTP methods and many other useful configurations so that you can focus more on your core functionality.

Advantages of Lambda Function URLs

  • Highly available
  • Scalable
  • Secured HTTPS service

What we will cover:

  • How to create an AWS Lambda https endpoint
  • How to handle different HTTP methods
  • Other available configurations.

Creating an AWS Lambda URL

Creating an AWS Lambda endpoint is very easy, go to the AWS Lambda Console, click on Create Function.

AWS Lambda Console

Choose the desired Function name and Runtime, scroll down a bit and click on Advanced settings. Enable the checkmark against the Enable function URL.

After enabling the above, some settings will pop up like Auth Type and CORS settings.

AWS Lambda Console

Choose your desired settings, for this tutorial we will select Auth Type as None so that anyone can access this endpoint and we will enable the CORS to allow access to our endpoint from any origin. Click on Create function to complete the process.

You can find the HTTPS url on the lambda function details.

AWS Console

Handling HTTP Methods

We will use the following python code to handle various HTTP request methods on our Lambda URL.

As you see from the code above, you can find the http method type from the event parameter we receive in our lambda_handler function. Similarly query params and request body is also present in the event object as queryStringParameters and body respectively. If you want to see what other things are present just print the event parameter.

Testing our Lambda URL

GET Request
POST Request
PUT Request

Other available configurations

If you go to the Configuration Tab and select Function URL, you can find a number of settings available for your AWS Lambda URL like

  • Adding origins who can access the URL.
  • Selecting the HTTP headers in your function response that you want to expose to origins that call your function URL
  • Selection the HTTP headers that origins can include in requests to your function URL
  • The maximum amount of time (in seconds) that browsers can cache results of a preflight request.
  • Allowed HTTP methods.

You can also map your HTTPS URL to your function alias, so if you map your URL with the $LATEST alias version your endpoint will function according to the newly updated lambda function code.

Thanks for reading, if you find this useful please share with your friends and colleagues.

--

--

Abhinav Singh

Software Engineer | Linkedin @cachedengineer | Twitter @cached_engineer