DEV Community

Cover image for How to Create Lambda function URLs

How to Create Lambda function URLs

AWS recently introduced AWS Lambda Function URLs. Built-in HTTPS Endpoints for Single-Function Microservices. It helps users to configure an HTTPS endpoint for a Lambda function without using any other AWS services such as AWS API Gateway or Application Load Balancer.

First of all, go through Architecture Diagram.
Image description

Create IAM role for Lambda function

In AWS management console search and go inside IAM service. Next create IAM Role for lambda function. Use Trusted entity type as AWS service and Use case as Lambda.
Image description
Image description

Use permissions as AWSLambdaBasicExecutionRole AWS managed policy.
Image description
Image description

Type role name as function-url-role.
Image description

Finally, click Create role button.
Image description

Create Lambda function

  • In AWS management console search and go inside Lambda service. Next click Create function button. Select Author from scratch and given function name as function-url-demo.
  • Select runtime as Python 3.9.
  • Expand Execution role and select Use an existing role. after that select previos step created Role name as function-url-role. Image description
  • After that expand Advanced settings and select Enable Function URL and Auth type as NONE.
  • Finally click Create function button. Image description

Test the function

  • Add following code part for Code source section lambda_function.py file.

lambda_function.py



import json
def lambda_handler(event, context):
    body = "Hello Lambda Function URL"
    statusCode = 200
    return {
        "statusCode": statusCode,
        "body": json.dumps(body),
        "headers": {
            "Content-Type": "application/json"
        }
    }


Enter fullscreen mode Exit fullscreen mode

Click Deploy button to deploy code.

  • After that we can Test the function. Go to Test section and add test event. Give the event name as Test1 and select hello-world template. Click save button. Image description Next click test button. you can see output as following. Image description

Test the function URL endpoints

You can use curl or Postman.

  • You can get function URL in Function overview section or go to
    configurations section and copy Function URL.
    Image description

  • You can use curl command. paste it your terminal, You can see
    response.
    curl -X GET '{{Your Function URL}}' -H 'Content-Type: application/json'
    Image description

  • In postman you use GET method & paste Function URL.
    Image description

By deleting AWS resources no longer using, you can prevent unnecessary charges to your AWS account. Open the Functions page in the Lambda console and select the function and go action section. After that click the Delete button.

Image description

Thanks for reading the Article.

References - https://aws.amazon.com/blogs/aws/announcing-aws-lambda-function-urls-built-in-https-endpoints-for-single-function-microservices/

Top comments (4)

Collapse
 
liyasthomas profile image
Liyas Thomas

Since you mentioned Postman to test API endpoints, we're building an open source {free} Postman alternative: Hoppscotch - API request builder for web. You can spin up the Lambda Function URLs directly from the browser window itself.

GitHub logo hoppscotch / hoppscotch

👽 Open source API development ecosystem - https://hoppscotch.io

Collapse
 
lasanthasilva profile image
Lasantha Sanjeewa Silva

Thanks for your information.

Collapse
 
racheal profile image
Racheal Walker

hey,
you can do this as well.
Steps to create Lambda Function URLs
1.Open the Functions page of the Lambda console.
2.Choose the name of the function that you want to create the function URL for.
3.Choose the Configuration tab, and then choose Function URL.
4.Choose Create function URL.
5.For Auth type, choose AWS_IAM or NONE. For more information about function URL authentication, see Security and auth model.
6.(Optional) Select Configure cross-origin resource sharing (CORS), and then configure the CORS settings for your function URL. For more information about CORS, see Cross-origin resource sharing (CORS).
7.Choose Save

Collapse
 
lasanthasilva profile image
Lasantha Sanjeewa Silva

Thanks for your information.