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.

Work with the database

The function keeps its data in a SQLite file at /tmp/movie-reviews.db, because /tmp is the only place Lambda lets you write.

Every time a container starts, the handler applies any pending Entity Framework Core migrations. If Database__SeedSampleData is true and the database is empty, it also seeds the sample movies, authors and reviews. Docker Compose turns that on. It’s off everywhere else, so a deployed function never starts life full of fake reviews.

Set ConnectionStrings__MovieReviews. To keep everything in memory:

Terminal window
docker run --rm -p 7350:8080 \
-e ConnectionStrings__MovieReviews="Data Source=MovieReviews;Mode=Memory;Cache=Shared" \
-e Database__SeedSampleData=true \
worksonmymachine-movies:local

After you change the data model in src/Infrastructure:

Terminal window
dotnet tool install --global dotnet-ef
dotnet ef migrations add AddDirectors \
--project ./src/Infrastructure \
--output-dir Databases/MovieReviews/Migrations \
--namespace WorksOnMyMachine.Movies.Infrastructure.Databases.MovieReviews.Migrations
sed -i '1s/^\xEF\xBB\xBF//' src/Infrastructure/Databases/MovieReviews/Migrations/*.cs

Without --namespace the migration lands in a namespace of its own, and the sed strips the byte order mark the tool adds. On macOS, use sed -i ''. Then make // <auto-generated /> the first line of the new <timestamp>_AddDirectors.cs, as it is in the other migrations, so the analysers and dotnet format leave it alone. Swap WorksOnMyMachine.Movies for your solution’s name.

The next container start applies it, and Make it yours adds a whole entity this way.

Everything database-shaped lives in Infrastructure, and every class there but DependencyInjection is internal. To move to DynamoDB, Aurora or anything else, implement the repository interfaces from Application (IMoviesRepository, IAuthorsRepository and IReviewsRepository) against the new store and register them in Infrastructure/DependencyInjection.cs. Application and Presentation don’t need to know it happened. That’s the whole sales pitch of Clean Architecture in one paragraph.