Introduction to Lambda Function URLs
Tags: lambda, aws, serverless
Published: 2023-11-27 19:01:31


Hi everyone,

I have been using Lambda service for the last 3 years. Whenever I want a public URL to trigger the lambda function immediately I used to go to API Gateway. 

There I have to do some steps like creating resources, and methods attaching lambda, deploying API, etc. Every time I used to wonder if there should be some easy way to do it

But never done any research on achieving this. Two days back doing some research for writing my next article I came across these Lambda Function URLs.

After getting to know about Lambda URLs, I literally felt like this 

![](https://cdn-images-1.medium.com/max/2000/1*mxxpWWzo7gR7JURTDO8aVw.gif)

Okay. Enough of my story. Let’s dive into the topic

**Lambda Function URLs:**

If you want a public URL to directly call a Lambda function without using API Gateway, you can use Lambda function URLs. It will give a public HTTP URL. We can call this URL like normal URL we daily use in our lives

**Creating a Lambda Function URL:**

* Visit the Lambda service from the AWS search

* Click on the Create Lambda function. Give a name for the function and select Runtime. I am selecting Python 3.9 as my function runtime

![](https://cdn-images-1.medium.com/max/3654/1*Y9w_LY2MjW9WRDpkz9X1BQ.png)

* Click on the Create Function button and wait for some time for the function to be created

* It will come with the basic code like this

![](https://cdn-images-1.medium.com/max/3320/1*71UIjAwKOqZpQxvCIKn4XQ.png)

* For testing, that code is enough. Now to create a public URL, Visit the configuration tab at the top of the Lambda code editor

![](https://cdn-images-1.medium.com/max/3322/1*nxdpaZ-cvVneTkYRVGaDQA.png)

* From the side menu click on Function URL and click on the Create Function URL button

![](https://cdn-images-1.medium.com/max/3322/1*Ys26wSk2vtXtig98FGif_g.png)

* You can find different Auth types like below

![](https://cdn-images-1.medium.com/max/2000/1*oFafFEwC7cR-f6VsoqWewA.png)

* AWS_IAM will allow permission granted users and roles to access the URL

* NONE will give access to the public. Anybody can access the Lambda Function using the URL

* From the Additional Settings, you can configure the CORS also

![](https://cdn-images-1.medium.com/max/2000/1*LPswu4YaGv_jwt768dA3Ag.png)

* You can define the origin you want to allow and can add needed headers.

![](https://cdn-images-1.medium.com/max/2000/1*MyH0e88gDNe0nlzDlzu6Jw.png)

* From the drop-down, you can select the methods you want for the function and click on save.

* Once the Function URL is generated, you can find the details like below

![](https://cdn-images-1.medium.com/max/2808/1*7yLRCZjo9f-MdLlUtfpRXw.png)

* You can copy the Function URL, put it in PostMan, and test it like the below

![](https://cdn-images-1.medium.com/max/3068/1*k2Ce8B2Y5ZehxSI8YcS14g.png)

* As I kept the Authe type as AWS_IAM, It’s giving forbidden as the response. Now I am changing it to NONE

![](https://cdn-images-1.medium.com/max/2000/1*1KZX4jWlr8vyb33QGKzK6Q.png)

* After that, I tried again. Now I am getting the correct response.

![](https://cdn-images-1.medium.com/max/3042/1*RgI0kfmG8Tevq3zAxXkYXg.png)

**Use cases:**

* We can use these Lambda Function URLs for webhooks

* For a quick API, static websites, or single-page applications, these are helpful

* For simple web applications, that don’t want to use API Gateway it is very helpful

* For me for simply writing a function and testing it directly, I feel these function URLs are very helpful.

There are so many use cases for now I can only think of these

**Limitations:**

* When you compare these Lambda Function URLs with API Gateway, these lack some security features API keys, Granular access control, etc.

* For restricting the HTTP Methods we need to implement our own logic in the Lambda, by default these don't provide any HTTP method restriction

* CORS configuration, if not configured correctly can lead to many security issues.

That’s all about Lambda Function URLs I got to know about in a little bit of time. If you know of any use cases I missed or any limitations you have feel free to comment. I am open to suggestions. 

Thanks, everyone, Have a good day.