/DotNetAwsEnv

AWS-Env Project for Loading SSM Variables into a .NET Environment

Primary LanguageC#MIT LicenseMIT

DotNetAwsEnv

DotNetAwsEnv Build License: MIT NuGet version

A .NET library to load AWS parameter store variables into the environment. This is based on the aws-env project for loading data into the environment.

Installation

Available on NuGet

Visual Studio:

PM> Install-Package DotNetAwsEnv

.NET CLI:

dotnet add package DotNetAwsEnv

Usage

Load parameters file

Load() or LoadAsync() will automatically search for variables in parameter store and inject them into the environment.

DotNetAwsEnv.AwsEnv.Load("ssm/path/prefix");
await DotNetAwsEnv.AwsEnv.LoadAsync("ssm/path/prefix", cancellationToken);

Using .NET Configuration provider

Integrating with the usual ConfigurationBuilder can be used as well:

var configuration = new ConfigurationBuilder()
    .AddDotNetAwsEnv("ssm/path/prefix")
    .Build();

This will inject these variables into the Configuration Provider and can be used across the application with IConfiguration.

If you use this method over the aws-env library and expect variables to loaded in the same order, it must come before the var builder = WebApplication.CreateBuilder(args); call.

This is because the host builder will inject certain pieces of information, such as ASPNETCORE_ENVIRONMENT and those will not be picked up if the configuration is loaded after the host is created with CreateBuilder.