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.
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.
Use permissions as AWSLambdaBasicExecutionRole AWS managed policy.
Type role name as function-url-role.
Finally, click Create role button.
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.
- After that expand Advanced settings and select Enable Function URL and Auth type as NONE.
- Finally click Create function button.
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"
}
}
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. Next click test button. you can see output as following.
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.
You can use curl command. paste it your terminal, You can see
response.
curl -X GET '{{Your Function URL}}' -H 'Content-Type: application/json'
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.
Thanks for reading the Article.
Top comments (4)
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.
hoppscotch / hoppscotch
π½ Open source API development ecosystem - https://hoppscotch.io
Thanks for your information.
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
Thanks for your information.