| Key | Value |
|---|---|
| Services | Lambda |
| Integrations | AWS CLI, Terraform |
| Categories | Serverless; REST API |
A demo application illustrating how to create a JavaScript Lambda function with a function URL using LocalStack. Lambda function URLs provide a dedicated HTTP(S) endpoint for invoking a Lambda function directly. The sample also demonstrates deploying the same setup using Terraform.
- A valid LocalStack for AWS license. Your license provides a
LOCALSTACK_AUTH_TOKENto activate LocalStack. - Docker
localstackCLIawslocalCLI- Terraform (optional, for Terraform-based deployment)
make checkmake installexport LOCALSTACK_AUTH_TOKEN=<your-auth-token>
make startDeploy the Lambda function and create a function URL:
awslocal lambda create-function \
--function-name localstack-lamba-url-example \
--runtime nodejs20.x \
--zip-file fileb://function.zip \
--handler index.handler \
--role arn:aws:iam::000000000000:role/cool-stacklifter
awslocal lambda create-function-url-config \
--function-name localstack-lamba-url-example \
--auth-type NONEYou will receive an HTTP URL in the form http://abcdefgh.lambda-url.us-east-1.localhost.localstack.cloud:4566. Invoke the Lambda function via HTTP POST:
curl -X POST \
'http://abcdefgh.lambda-url.us-east-1.localhost.localstack.cloud:4566/' \
-H 'Content-Type: application/json' \
-d '{"num1": "10", "num2": "10"}'Expected output:
The product of 10 and 10 is 100
You can automate the Lambda function and function URL creation using Terraform:
terraform init
terraform plan
terraform apply --auto-approveSince we are using LocalStack, no actual AWS resources will be created. LocalStack creates ephemeral development resources that are automatically cleaned up when you stop LocalStack (localstack stop).
This code is available under the Apache 2.0 license.