A Guide to AWS Lambda Function URLs and Lambda Layers
Learn how to create Lambda functions, configure Function URLs, add Lambda Layers, and monitor your functions, a fast way to run code in the cloud without managing servers.
4 min read
In this guide, you will learn how to create Lambda Functions, configure Function URLs, add Lambda Layers, and more.
Why AWS Lambda
- Serverless simplicity. No server management is required.
- Pay only for the compute time you use.
- Supports multiple programming languages including Python, Node.js, Java, Go, .NET, Ruby, and custom runtimes.
- Automatically scales to handle any number of requests.
- Integrates easily with AWS services and with external tools.
Step-by-Step Guide
Total hands-on time: ~30 minutes
Create a Lambda Function
- Log in to the AWS Management Console, search for “Lambda” in the search bar, and select it.
- Select “Create function.”
- Under “Author from scratch” fill in the following:
- Function name: Use something descriptive such as WebhookHandler.
- Runtime: Choose the programming language you want to use such as Python 3.12 or Node.js 20.x.
- Architecture: Choose either arm64 or x86_64 based on your use case.
- For permissions choose “Create a new role with basic Lambda permissions” so that the function can write logs to CloudWatch.
- Select “Create function.”
- Add Your Code: You can edit your code directly in the AWS console or upload a ZIP file containing your code (example code provided below).
- Select “Deploy” to save your changes.
Example Python handler:
def lambda_handler(event, context):
print("Received event:", event)
return {
"statusCode": 200,
"body": "Hello from AWS Lambda!"
}Create and Configure a Function URL
A Function URL allows you to call your Lambda directly over HTTP without setting up API Gateway.
- Open your Lambda function.
- Go to “Configuration” and select “Function URL.”
- Select “Create function URL.”
- For authentication type choose one of the following:
- NONE: Allows public access. This is good for testing but may not be secure for production.
- AWS_IAM: Requires AWS credentials to call the function.
- Enable CORS if the Lambda will be called from a browser based application.
- Select “Save.” You will receive a URL similar to: https://abc123.lambda-url.us-east-1.on.aws/
- Test the Function URL:
- From a terminal run “curl https://abc123.lambda-url.us-east-1.on.aws/” or paste the URL in a web browser. You should see the function response.
- Secure Your Function URL:
- If you select NONE for authentication type you should still add your own security.
- You can require a secret key in headers or query parameters.
- You can validate and sanitize all inputs.
- For sensitive workloads it is best to use AWS_IAM or API Gateway with authentication.
Create Lambda Layers
Lambda Layers let you share code, libraries, or other assets across multiple functions so you do not need to duplicate them. In this section we will walk through an example that adds the Requests module.
First, prepare the package locally:
mkdir python
[PATH_TO_PYTHON] -m pip install requests -t python/Then, zip and upload the Layer:
- Zip the folder you just created.
- In AWS Console select “Lambda” then Layers then “Create layer.”
- Enter a name such as “requests-layer” (being descriptive is recommended).
- Upload the file “python.zip.”
- Select the compatible runtime (for example, Python 3.12) and configure the other settings per your use case.
- Select “Create.”
Next, attach the Layer to your function:
- Open your Lambda function.
- Go to “Layers” (scroll down in the “Code” tab) and select “Add a layer.”
- Choose “Custom layers” then select your layer.
- Select “Add.”
Last, use the dependency in your function:
import requests
def lambda_handler(event, context):
r = requests.get("https://[SOME_WEBSITE].com")
return {
"statusCode": 200,
"body": r.text
}Monitor and Debug
AWS automatically sends logs from Lambda to CloudWatch Logs.
- In the Lambda console open your function.
- Select “Monitor” then “View CloudWatch logs.”
- Review the most recent log streams to see output from your function and troubleshoot errors.
Pros and Cons of AWS Lambda for Quick Automations
Pros
- No server setup or maintenance required.
- Automatically scales to handle demand.
- Very cost effective for infrequent workloads.
- Integrates directly with many AWS services.
Cons
- Maximum execution time is fifteen minutes per run.
- Cold start latency for functions that are not used frequently.
- Limited control over the execution environment.
Overall
AWS Lambda is a fast and flexible way to run code in the cloud without the overhead of managing servers. By combining Function URLs with Lambda Layers you can quickly create public endpoints, handle incoming requests, and share code across multiple functions while keeping costs low and efficiency high.
Need Help Building Serverless Automations?
At Odezzi LLC we design and deploy scalable automation solutions using AWS Lambda and other modern cloud based tools. Whether you need a simple webhook handler or a large scale automation pipeline we can help you launch quickly and scale effectively. Contact us today to learn more.
*Odezzi LLC is not affiliated with Amazon Web Services. All product names, trademarks, and registered trademarks are property of their respective owners.
