Skip to content
Clean Lambda Function
Lean Mean Clean Apps

Five templates, one brand, one search box. Everything in the docs is in here, including the bits we hoped you'd skim.

Try one of these

Results say which template they came from, so you won't end up reading about Lambda when you wanted GraphQL. Again.

Run it locally

The image is built on the AWS Lambda .NET base image, which includes the Lambda runtime interface emulator. Your function runs locally exactly the way Lambda runs it, just with fewer invoices.

Terminal window
docker compose up -d --build

Compose builds the run stage, publishes port 7350, turns on sample data, and starts an OpenTelemetry Collector and the Aspire dashboard next to it. Shut it down with docker compose down.

Then invoke it from another terminal:

Terminal window
curl -X POST "http://localhost:7350/2015-03-31/functions/function/invocations" -d '{"limit":5}'

With Docker Compose, the function sends its traces, metrics and logs over OTLP to an OpenTelemetry Collector, which forwards them to the Aspire dashboard at http://localhost:7352. Each invocation is one trace: the function’s span from the OpenTelemetry Lambda wrapper, with the use case under it. Traces and metrics are flushed before the function returns, so they’re there by the time curl is. The logs still go to the console too, so docker compose logs function works as it always did. The dashboard has no login, and the collector accepts OTLP from anyone on ports 7353 and 7354. That’s on purpose, so there’s nothing to sign in to on your machine, and it’s why the compose file is for your machine only. Don’t run it anywhere other people can reach.

Run the image on its own and nothing is exported, because OTEL_EXPORTER_OTLP_ENDPOINT isn’t set. Set it to send the telemetry to a collector of your own.

The image runs GetMovies by default. The same image also has GetAuthors and GetReviews, and the HttpGetMovies, HttpGetAuthors and HttpGetReviews functions that take an API Gateway event. Pass the function’s full handler name to docker run to start a different one.

Terminal window
docker run --rm -p 7350:8080 -e Database__SeedSampleData=true worksonmymachine-movies:local \
"Presentation::WorksOnMyMachine.Movies.Presentation.LambdaFunction.Handler_GetReviews_Generated::GetReviews"
curl -X POST "http://localhost:7350/2015-03-31/functions/function/invocations" \
-d '{"movieId":"cb188ef6-14e7-f85f-2f78-924c2ab26b28","limit":2}'

The sample data uses a fixed seed, so that movie id is the same on every machine. See the function reference for every request and response.

Terminal window
dotnet test

The tests build their own in-memory SQLite databases from the same migrations and seed, so nothing touches the database file in /tmp. Test your changes covers where a test goes, how the tests are written and how to check coverage before CI does.

The Dockerfile has a stage for each job, so you can build only what you need.

Stage What it does
build Restores and builds the solution
test Runs every test with coverage, and saves the result instead of failing the build
results Exports the test results, the coverage report and the exit code to your machine
publish Publishes the Presentation project
run The Lambda image you deploy
Terminal window
docker build . --target results --output type=local,dest=out

A failing test doesn’t fail the build, so the results still come out. Check out/exit-code: anything other than 0 means a test failed, and a pipeline built on these stages should fail on it.

Terminal window
docker build . --target run --tag worksonmymachine-movies:latest \
--build-arg VERSION_PREFIX=1.2.3 --build-arg VERSION_SUFFIX=beta