diff --git a/.github/workflows/validate-pr-title.yaml b/.github/workflows/validate-pr-title.yaml index f9394fcc..38fae0aa 100644 --- a/.github/workflows/validate-pr-title.yaml +++ b/.github/workflows/validate-pr-title.yaml @@ -44,6 +44,7 @@ jobs: ci github core + docs requireScope: false subjectPattern: ^[a-z].* subjectPatternError: Subject must start with lowercase letter diff --git a/docs/guides/configuration.md b/docs/guides/configuration.md index b7975ce8..fc5f82e9 100644 --- a/docs/guides/configuration.md +++ b/docs/guides/configuration.md @@ -7,12 +7,37 @@ shutdown windows, serializer choices, etc.). This guide covers both layers. ## How Configuration Is Built -`LambdaApplication.CreateBuilder()` wires up the standard .NET defaults: - -1. `appsettings.json` (optional) in the application root. -2. `appsettings.{Environment}.json` (optional) based on `DOTNET_ENVIRONMENT`/`ASPNETCORE_ENVIRONMENT`. -3. User secrets (Development only). -4. Environment variables (`AWS_`, `DOTNET_`, and general variables). +`LambdaApplication.CreateBuilder()` wires up the standard .NET defaults unless you pass +`new LambdaApplicationOptions { DisableDefaults = true }`. When defaults are enabled, configuration +providers are added in the following order (later entries override earlier ones): + +1. Environment variables prefixed with `AWS_` (Lambda metadata such as `AWS_LAMBDA_FUNCTION_NAME`). +2. Environment variables prefixed with `DOTNET_` (host defaults such as `DOTNET_ENVIRONMENT` or `DOTNET_CONTENTROOT`). +3. `appsettings.json` (optional) in the application root. +4. `appsettings.{Environment}.json` (optional) based on `DOTNET_ENVIRONMENT`. +5. User secrets (Development only, resolved from the entry assembly). +6. All remaining environment variables (no prefix filter). + +!!! warning "`ASPNETCORE_` Prefixed Environment Variable" + Enviroment variables with the `ASPNETCORE_` prefix are not automatically loaded by `CreateBuilder()` and must be added manually. As such, the enviroment cannot be set using the `ASPNETCORE_ENVIRONMENT` environment variable. + + To load environment variables prefixed with `ASPNETCORE_` after calling `CreateBuilder()`, you can add the following code: + + ```csharp + var builder = LambdaApplication.CreateBuilder(); + builder.Configuration.AddEnvironmentVariables("ASPNETCORE_"); + ``` + + If you need to use `ASPNETCORE_` prefixed environment variables when creating the `LambdaApplicationBuilder`, you can add the following code: + + ```csharp + var configuration = new ConfigurationManager(); + configuration.AddEnvironmentVariables("ASPNETCORE_"); + + var builder = LambdaApplication.CreateBuilder( + new LambdaApplicationOptions { Configuration = configuration } + ); + ``` The builder also binds the `AwsLambdaHost` section (from JSON or environment variables) into `LambdaHostOptions` so framework settings can live next to your app configuration. diff --git a/docs/index.md b/docs/index.md index 1b1a0a15..965af824 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,3 +1,7 @@ +--- +title: "" +--- + # Build AWS Lambda Functions with .NET Hosting Patterns [![Main Build](https://github.com/j-d-ha/aws-lambda-host/actions/workflows/main-build.yaml/badge.svg)](https://github.com/j-d-ha/aws-lambda-host/actions/workflows/main-build.yaml) diff --git a/examples/AwsLambda.Host.Example.Events/Properties/launchSettings.json b/examples/AwsLambda.Host.Example.Events/Properties/launchSettings.json index 6b37dc1a..a348821c 100644 --- a/examples/AwsLambda.Host.Example.Events/Properties/launchSettings.json +++ b/examples/AwsLambda.Host.Example.Events/Properties/launchSettings.json @@ -5,7 +5,7 @@ "commandName": "Project", "environmentVariables": { "AWS_LAMBDA_RUNTIME_API": "localhost:5050", - "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development", "AWS_LAMBDA_LOG_FORMAT": "JSON", "AWS_LAMBDA_LOG_LEVEL": "DEBUG" } diff --git a/examples/AwsLambda.Host.Example.HelloWorldAot/Properties/launchSettings.json b/examples/AwsLambda.Host.Example.HelloWorldAot/Properties/launchSettings.json index 6b37dc1a..a348821c 100644 --- a/examples/AwsLambda.Host.Example.HelloWorldAot/Properties/launchSettings.json +++ b/examples/AwsLambda.Host.Example.HelloWorldAot/Properties/launchSettings.json @@ -5,7 +5,7 @@ "commandName": "Project", "environmentVariables": { "AWS_LAMBDA_RUNTIME_API": "localhost:5050", - "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development", "AWS_LAMBDA_LOG_FORMAT": "JSON", "AWS_LAMBDA_LOG_LEVEL": "DEBUG" } diff --git a/examples/AwsLambda.Host.Example.Lifecycle/Properties/launchSettings.json b/examples/AwsLambda.Host.Example.Lifecycle/Properties/launchSettings.json index 6b37dc1a..a348821c 100644 --- a/examples/AwsLambda.Host.Example.Lifecycle/Properties/launchSettings.json +++ b/examples/AwsLambda.Host.Example.Lifecycle/Properties/launchSettings.json @@ -5,7 +5,7 @@ "commandName": "Project", "environmentVariables": { "AWS_LAMBDA_RUNTIME_API": "localhost:5050", - "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development", "AWS_LAMBDA_LOG_FORMAT": "JSON", "AWS_LAMBDA_LOG_LEVEL": "DEBUG" } diff --git a/examples/AwsLambda.Host.Example.OpenTelemetry/Properties/launchSettings.json b/examples/AwsLambda.Host.Example.OpenTelemetry/Properties/launchSettings.json index 075e2dbb..5353021c 100644 --- a/examples/AwsLambda.Host.Example.OpenTelemetry/Properties/launchSettings.json +++ b/examples/AwsLambda.Host.Example.OpenTelemetry/Properties/launchSettings.json @@ -5,7 +5,7 @@ "commandName": "Project", "environmentVariables": { "AWS_LAMBDA_RUNTIME_API": "localhost:5050", - "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development", "AWS_LAMBDA_LOG_FORMAT": "JSON", "AWS_LAMBDA_LOG_LEVEL": "DEBUG" } diff --git a/mkdocs.yml b/mkdocs.yml index ccc88842..d8d76c79 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -86,6 +86,9 @@ markdown_extensions: - def_list - pymdownx.tasklist: custom_checkbox: true + - toc: + permalink: true + permalink_title: Anchor link to this section for reference watch: - ./docs/ diff --git a/tasks/LocalDevTasks.yml b/tasks/LocalDevTasks.yml index 9bcbf9b3..b6b5d94a 100644 --- a/tasks/LocalDevTasks.yml +++ b/tasks/LocalDevTasks.yml @@ -47,4 +47,11 @@ tasks: desc: Start the AWS Lambda test tool silent: true cmds: - - dotnet lambda-test-tool start --lambda-emulator-port 5050 \ No newline at end of file + - dotnet lambda-test-tool start --lambda-emulator-port 5050 + + run-docs: + desc: Run MKDocs server locally + silent: true + cmds: + - uv sync + - uv run mkdocs serve --livereload \ No newline at end of file