Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions docs/guides/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ builder.Services.ConfigureLambdaHostOptions(options =>
});
```

| Option | Type | Default | Description |
|--------------------------------|--------------------------|------------------------------------|-----------------------------------------------------------------------------|
| `InitTimeout` | `TimeSpan` | 5 seconds | Maximum time all `OnInit` handlers collectively have before cancellation. |
| `InvocationCancellationBuffer` | `TimeSpan` | 3 seconds | Buffer subtracted from remaining time before the invocation token fires. |
| `ShutdownDuration` | `TimeSpan` | `ShutdownDuration.ExternalExtensions` (500β€―ms) | Expected window between SIGTERM and SIGKILL. |
| `ShutdownDurationBuffer` | `TimeSpan` | 50β€―ms | Safety margin deducted from `ShutdownDuration` to guarantee cleanup. |
| `ClearLambdaOutputFormatting` | `bool` | `false` | Automatically register the built-in OnInit handler that clears console formatting. |
| `BootstrapHttpClient` | `HttpClient?` | `null` | Custom client for the Lambda bootstrap runtime API. |
| `BootstrapOptions` | `LambdaBootstrapOptions` | `new()` | Low-level runtime bootstrap configuration (timeouts, heartbeats, etc.). |
| Option | Type | Default | Description |
|--------------------------------|--------------------------|-----------------------------------------------|------------------------------------------------------------------------------------|
| `InitTimeout` | `TimeSpan` | 5 seconds | Maximum time all `OnInit` handlers collectively have before cancellation. |
| `InvocationCancellationBuffer` | `TimeSpan` | 500 milliseconds | Buffer subtracted from remaining time before the invocation token fires. |
| `ShutdownDuration` | `TimeSpan` | `ShutdownDuration.ExternalExtensions` (500ms) | Expected window between SIGTERM and SIGKILL. |
| `ShutdownDurationBuffer` | `TimeSpan` | 50ms | Safety margin deducted from `ShutdownDuration` to guarantee cleanup. |
| `ClearLambdaOutputFormatting` | `bool` | `false` | Automatically register the built-in OnInit handler that clears console formatting. |
| `BootstrapHttpClient` | `HttpClient?` | `null` | Custom client for the Lambda bootstrap runtime API. |
| `BootstrapOptions` | `LambdaBootstrapOptions` | `new()` | Low-level runtime bootstrap configuration (timeouts, heartbeats, etc.). |

### `InitTimeout`

Expand Down Expand Up @@ -142,9 +142,9 @@ lambda.OnShutdown(async (ITelemetry telemetry, CancellationToken ct) =>

Choose from the provided constants when possible:

- `ShutdownDuration.NoExtensions` – No extensions installed (0β€―ms window).
- `ShutdownDuration.InternalExtensions` – Only internal extensions (300β€―ms).
- `ShutdownDuration.ExternalExtensions` – External extension installed (500β€―ms, default).
- `ShutdownDuration.NoExtensions` – No extensions installed (0ms window).
- `ShutdownDuration.InternalExtensions` – Only internal extensions (300ms).
- `ShutdownDuration.ExternalExtensions` – External extension installed (500ms, default).
- Any custom `TimeSpan` when your environment requires more/less time.

### `ClearLambdaOutputFormatting`
Expand Down
12 changes: 6 additions & 6 deletions docs/guides/dependency-injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ If your handler doesn't need the Lambda payload, omit the `[Event]` parameter en
!!! tip "Cancellation buffers"
The cancellation token fires slightly **before** AWS kills the process:

- The runtime subtracts `LambdaHostOptions.InvocationCancellationBuffer` (default 3s) from the
- The runtime subtracts `LambdaHostOptions.InvocationCancellationBuffer` (default 500ms) from the
remaining time when creating the token.
- Always pass it down to outbound SDK calls and database queries so you can stop work cleanly.

Expand Down Expand Up @@ -131,12 +131,12 @@ lambda.MapHandler((

## Host-Specific Pitfalls

| Pitfall | Impact | Fix |
|---------|--------|-----|
| Pitfall | Impact | Fix |
|---------------------------------------|-----------------------------------------------------|-----------------------------------------------------------------------------------------|
| Singleton depends on a scoped service | Scoped instance from first invocation leaks forever | Inject `IServiceProvider`, create a scope, resolve the scoped service inside the method |
| Storing scoped services in singletons | `ObjectDisposedException` on later invocations | Keep scoped dependencies scoped; pass data instead of services |
| Over-injecting handlers | Hard-to-test functions with 8+ services | Move orchestration into services; keep handlers thin |
| Forgetting cancellation tokens | Lambda kills the environment mid-work | Always inject `CancellationToken` and pass it down |
| Storing scoped services in singletons | `ObjectDisposedException` on later invocations | Keep scoped dependencies scoped; pass data instead of services |
| Over-injecting handlers | Hard-to-test functions with 8+ services | Move orchestration into services; keep handlers thin |
| Forgetting cancellation tokens | Lambda kills the environment mid-work | Always inject `CancellationToken` and pass it down |

## Key Takeaways

Expand Down
4 changes: 2 additions & 2 deletions src/AwsLambda.Host/Core/Options/LambdaHostOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public class LambdaHostOptions
/// Gets or sets the buffer duration subtracted from the Lambda function's remaining
/// invocation time when creating cancellation tokens.
/// </summary>
/// <remarks>Default is 3 seconds.</remarks>
public TimeSpan InvocationCancellationBuffer { get; set; } = TimeSpan.FromSeconds(3);
/// <remarks>Default is 500 milliseconds.</remarks>
public TimeSpan InvocationCancellationBuffer { get; set; } = TimeSpan.FromMilliseconds(500);

/// <summary>
/// Gets or sets the duration between when AWS sends SIGTERM and SIGKILL to the Lambda
Expand Down
Loading