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.
Build and run
Section titled “Build and run”docker compose up -d --buildCompose 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.
docker build . --target run --tag worksonmymachine-movies:localdocker run --rm -p 7350:8080 -e Database__SeedSampleData=true worksonmymachine-movies:localThen invoke it from another terminal:
curl -X POST "http://localhost:7350/2015-03-31/functions/function/invocations" -d '{"limit":5}'See the telemetry
Section titled “See the telemetry”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.
Try the other functions
Section titled “Try the other functions”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.
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.
Run the tests
Section titled “Run the tests”dotnet testThe 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.
Run just one part of the Dockerfile
Section titled “Run just one part of the Dockerfile”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 |
docker build . --target results --output type=local,dest=outA 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.
Stamp a version
Section titled “Stamp a version”docker build . --target run --tag worksonmymachine-movies:latest \ --build-arg VERSION_PREFIX=1.2.3 --build-arg VERSION_SUFFIX=beta