Kanject.Core.Api.Aws.Extensions 3.8.3

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Kanject.Core.Api.Aws.Extensions --version 3.8.3
                    
NuGet\Install-Package Kanject.Core.Api.Aws.Extensions -Version 3.8.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Kanject.Core.Api.Aws.Extensions" Version="3.8.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kanject.Core.Api.Aws.Extensions" Version="3.8.3" />
                    
Directory.Packages.props
<PackageReference Include="Kanject.Core.Api.Aws.Extensions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Kanject.Core.Api.Aws.Extensions --version 3.8.3
                    
#r "nuget: Kanject.Core.Api.Aws.Extensions, 3.8.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Kanject.Core.Api.Aws.Extensions@3.8.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Kanject.Core.Api.Aws.Extensions&version=3.8.3
                    
Install as a Cake Addin
#tool nuget:?package=Kanject.Core.Api.Aws.Extensions&version=3.8.3
                    
Install as a Cake Tool

Kanject.Core.Api.Aws.Extensions

Kanject.Core.Api.Aws.Extensions adds AWS-specific plumbing for ASP.NET Core services and Lambda functions: loading configuration from AWS Systems Manager Parameter Store, turning PrintInConsole output into single-line JSON that CloudWatch Logs Insights can query, and reading the caller's country code from CDN headers.

Installation

dotnet add package Kanject.Core.Api.Aws.Extensions

Targets .NET 8, .NET 9 and .NET 10. It depends on Amazon.Extensions.Configuration.SystemsManager, AWSSDK.SimpleSystemsManagement and Kanject.Core.Api.Abstractions.

Quick start

using Kanject.Core.Api.Aws.Extensions.PrintInConsole;
using Kanject.Core.Api.Aws.Extensions.Vault.ParameterStore;

var builder = WebApplication.CreateBuilder(args);

#if DEBUG
// Local: path, profile and region come from appsettings (AppSettings section).
builder.AddAwsSystemManagerParameterStore(fetchSecretPathFromAppSettings: true);
#else
// Deployed: path comes from the SECRET_PARAMETER_PATHNAME environment variable.
builder.AddAwsSystemManagerParameterStore();
#endif

builder.Services.AddPrintInConsoleCloudWatch(options => options.ServiceName = "orders-api");

var app = builder.Build();
app.Run();

Parameter Store configuration

AddAwsSystemManagerParameterStore loads every parameter under a path into IConfiguration using Amazon.Extensions.Configuration.SystemsManager. The path prefix is stripped and the remaining / segments become :, so /orders-api/prod/Database/ConnectionString under the path /orders-api/prod/ is read as configuration["Database:ConnectionString"].

Each form exists on both WebApplicationBuilder and IConfigurationBuilder (use the latter in Lambda functions that build configuration without a web host):

Call Parameter path from Credentials and region
AddAwsSystemManagerParameterStore() SECRET_PARAMETER_PATHNAME environment variable AWS SDK defaults (for example, the Lambda execution role)
AddAwsSystemManagerParameterStore(fetchSecretPathFromAppSettings: true) AppSettings:SecretParameterPathName Named profile AppSettings:AwsProfile, region AppSettings:AwsRegion
AddAwsSystemManagerParameterStore(parameterPath, profile, region) The parameterPath argument The named profile, and region as a system name such as eu-west-2

For the app-settings form, the values are read from the configuration built so far; pass an IConfiguration as the second argument to read them from somewhere else:

{
  "AppSettings": {
    "SecretParameterPathName": "/orders-api/dev/",
    "AwsProfile": "dev",
    "AwsRegion": "eu-west-2"
  }
}

The app-settings and explicit forms require a named AWS profile, which makes them a fit for local development; in Lambda or containers use the environment-variable form so the SDK's default credential chain applies. The app-settings and explicit forms throw at startup when a required value is missing; the environment-variable form does not check the variable itself, so make sure it is set.

CloudWatch-friendly PrintInConsole

PrintInConsole (from Kanject.Core) writes plain text by default. AddPrintInConsoleCloudWatch() routes it through a handler that writes one JSON object per line — the format CloudWatch Logs Insights discovers fields from automatically — so existing call sites need no changes.

1. Enable the interceptor in the project that makes the calls

<PropertyGroup>
  <EnablePrintInConsoleInterceptor>true</EnablePrintInConsoleInterceptor>
</PropertyGroup>

The routing is done by a compile-time interceptor generator from Kanject.Core.Annotations. Only PrintInConsole calls compiled in a project with this property set are routed; calls compiled elsewhere keep the default console output.

2. Register the handler

using Kanject.Core.Api.Aws.Extensions.PrintInConsole;

builder.Services.AddPrintInConsoleCloudWatch(options =>
{
    options.ServiceName = "payment-api";   // added to every entry
    options.IncludeData = true;             // set false to drop the data array
});

The handler is installed by a hosted service when the host starts and removed when it stops; calls made before startup (for example while building configuration) use the default output.

Output

using Kanject.Core.SystemConsole.Extensions;

"Cache performance".PrintInConsole(tag: "Performance", data: new object[] { new { HitRate = 0.94 } });
{"timestamp":"2026-03-20T10:30:02.0000000Z","level":"Information","message":"Cache performance","tag":"Performance","service":"payment-api","data":[{"hitRate":0.94}]}
Field Present Content
timestamp Always UTC, ISO 8601 round-trip format
level Always Trace, Debug, Information, Warning, Error or Critical
message Always ToString() of the printed value
tag When a tag is passed The tag argument
service When ServiceName is set The configured service name
data When extra data is passed and IncludeData is true The data array, serialized with camel-case property names

Severity

The interceptor generator infers level at compile time: calls inside a catch block or with an Exception argument become Error, and error/warning/debug keywords in the tag or string literal select the matching level; everything else is Information. Pass a level explicitly to override the inference:

using Kanject.Core.SystemConsole;
using Kanject.Core.SystemConsole.Extensions;

"Error code lookup table loaded".PrintInConsole(ConsolePrintLogLevel.Information);

Example Logs Insights queries

fields @timestamp, level, message, tag, service
| filter level = "Error"
| sort @timestamp desc
| limit 50
stats count(*) as errorCount by service
| filter level = "Error"
| sort errorCount desc

ILogger bridge or CloudWatch JSON?

Kanject.Core also offers services.AddPrintInConsoleLogging(), which forwards PrintInConsole to ILogger. Use that when the application already has logging providers configured; use AddPrintInConsoleCloudWatch() for Lambda functions that write straight to CloudWatch without a logging framework. Don't register both — each replaces the same static handler, and the last one to start wins.

Client country code

using Kanject.Core.Api.Aws.Extensions.Controller;

var country = this.GetClientCountryCode();   // inside a controller action

GetClientCountryCode() returns the first header present among X-Country, CloudFront-Viewer-Country and CF-IPCountry, or null. These headers are only trustworthy when your CDN or load balancer sets or overwrites them — a client can send any of them directly.

Public surface at a glance

Type or member Namespace Purpose
AddAwsSystemManagerParameterStore(...) Kanject.Core.Api.Aws.Extensions.Vault.ParameterStore Adds Parameter Store as a configuration source
AddPrintInConsoleCloudWatch(configure) Kanject.Core.Api.Aws.Extensions.PrintInConsole Routes PrintInConsole to single-line JSON
PrintInConsoleCloudWatchOptions Kanject.Core.Api.Aws.Extensions.PrintInConsole ServiceName (default null), IncludeData (default true)
GetClientCountryCode() Kanject.Core.Api.Aws.Extensions.Controller Country code from CDN headers, on any ControllerBase
Package Role Availability
Kanject.Core PrintInConsole, ConsolePrintLogLevel and the ILogger bridge (AddPrintInConsoleLogging) nuget.org
Kanject.Core.Annotations The compile-time PrintInConsole interceptor generator nuget.org
Kanject.Core.Api.Abstractions Response models and exceptions (dependency of this package) nuget.org
Kanject.Core.Api Controllers, exception and tenant middleware (Kanject envelope errors) nuget.org
Kanject.Core.ApiV2 Controllers, exception and tenant middleware (Problem Details errors) nuget.org

License

Licensed under the Kanject Code Libraries License Agreement (KCLLA); the full text ships in this package as LICENSE.md. Organizations whose trailing-twelve-month gross revenue and total funding raised are each below US$250,000 may use it at no cost under the Free Tier. At or above either threshold a commercial license is required — contact commercial@kanjectbusiness.com.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.10.0 72 10/5/2026
3.9.0 80 10/2/2026
3.8.3 73 10/1/2026
3.8.2 91 9/29/2026
3.8.1 105 9/27/2026
3.8.0 92 9/27/2026
3.7.7 95 9/26/2026
3.7.6 123 9/7/2026
3.7.5 101 8/27/2026
3.7.4 107 8/22/2026
3.7.3 119 8/10/2026
3.7.2 110 8/9/2026
3.7.1 119 8/5/2026
3.7.0 128 8/5/2026
3.6.0 114 8/3/2026
3.5.7 122 7/30/2026
3.5.6 128 7/18/2026
3.5.5 144 7/13/2026
3.5.4 121 7/11/2026
3.5.3 124 7/11/2026
Loading failed