![]() |
VOOZH | about |
dotnet add package Opc.AwsSettings --version 1.2.3
NuGet\Install-Package Opc.AwsSettings -Version 1.2.3
<PackageReference Include="Opc.AwsSettings" Version="1.2.3" />
<PackageVersion Include="Opc.AwsSettings" Version="1.2.3" />Directory.Packages.props
<PackageReference Include="Opc.AwsSettings" />Project file
paket add Opc.AwsSettings --version 1.2.3
#r "nuget: Opc.AwsSettings, 1.2.3"
#:package Opc.AwsSettings@1.2.3
#addin nuget:?package=Opc.AwsSettings&version=1.2.3Install as a Cake Addin
#tool nuget:?package=Opc.AwsSettings&version=1.2.3Install as a Cake Tool
A .NET library that simplifies loading configuration from AWS services including Parameter Store, Secrets Manager, and AppConfig into your application's configuration system.
IConfiguration systemInstall the NuGet package:
dotnet add package Opc.AwsSettings
using Microsoft.Extensions.Hosting;
var host = Host.CreateDefaultBuilder(args)
.AddAwsSettings() // Add AWS configuration sources
.ConfigureServices(services =>
{
// Your service configuration
})
.Build();
await host.RunAsync();
using Microsoft.Extensions.Configuration;
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddAwsSettings() // Add AWS configuration sources
.Build();
Configure the library using the AwsSettings section in your appsettings.json:
{
"AwsSettings": {
"ReloadAfter": "00:05:00",
"ParameterStore": {
"Paths": ["/myapp/prod"],
"Keys": []
},
"SecretsManager": {
"LoadAll": false,
"AcceptedSecretArns": [],
"Prefix": null,
"Optional": false
},
"AppConfig": {
"ApplicationIdentifier": "my-app",
"UseLambdaCacheLayer": false,
"ConfigurationProfiles": []
}
}
}
Load all parameters under a specific path prefix:
{
"AwsSettings": {
"ParameterStore": {
"Paths": ["/myservice"]
}
}
}
If your Parameter Store contains:
/myservice/Database/ConnectionString = "Server=..."/myservice/Database/MaxPoolSize = "100"/myservice/Api/Endpoint = "https://api.example.com"They will be mapped to:
{
"Database": {
"ConnectionString": "Server=...",
"MaxPoolSize": "100"
},
"Api": {
"Endpoint": "https://api.example.com"
}
}
Use custom aliases to map Parameter Store keys to cleaner configuration names:
{
"AwsSettings": {
"ParameterStore": {
"Keys": [
{
"Path": "/aws/reference/secretsmanager/prod-db-credentials",
"Alias": "Database:ConnectionString"
},
{
"Path": "/myservice/config/api-key",
"Alias": "ApiSettings:Key",
"Optional": true
}
]
}
}
}
Reference Secrets Manager values through Parameter Store:
{
"AwsSettings": {
"ParameterStore": {
"Keys": [
{
"Path": "/aws/reference/secretsmanager/my-secret",
"Alias": "MySecret"
}
]
}
}
}
Load all secrets from Secrets Manager:
{
"AwsSettings": {
"SecretsManager": {
"LoadAll": true,
"Optional": false
}
}
}
{
"AwsSettings": {
"SecretsManager": {
"LoadAll": false,
"AcceptedSecretArns": [
"arn:aws:secretsmanager:us-east-1:123456789012:secret:prod/database",
"arn:aws:secretsmanager:us-east-1:123456789012:secret:prod/api-keys"
]
}
}
}
Filter secrets by name prefix:
{
"AwsSettings": {
"SecretsManager": {
"LoadAll": true,
"Prefix": "prod/myapp/"
}
}
}
{
"AwsSettings": {
"AppConfig": {
"ApplicationIdentifier": "my-application",
"ConfigurationProfiles": [
{
"Identifier": "my-config-profile",
"Optional": false
},
{
"Identifier": "feature-flags",
"Optional": true
}
]
}
}
}
For AWS Lambda functions, enable the cache layer for improved performance:
{
"AwsSettings": {
"AppConfig": {
"ApplicationIdentifier": "my-application",
"UseLambdaCacheLayer": true,
"ConfigurationProfiles": [
{
"Identifier": "my-config-profile"
}
]
}
}
}
Enable automatic reloading of configuration at specified intervals:
{
"AwsSettings": {
"ReloadAfter": "00:05:00", // Reload every 5 minutes
"ParameterStore": {
"Paths": ["/myapp"]
}
}
}
The library respects the ASPNETCORE_ENVIRONMENT or DOTNET_ENVIRONMENT variables:
var host = Host.CreateDefaultBuilder(args)
.AddAwsSettings() // Automatically uses current environment
.Build();
Or specify the environment explicitly:
var configuration = new ConfigurationBuilder()
.AddAwsSettings(environmentName: "Production")
.Build();
public class DatabaseSettings
{
public string ConnectionString { get; set; }
public int MaxPoolSize { get; set; }
}
// In Program.cs
services.Configure<DatabaseSettings>(
configuration.GetSection("Database")
);
// In your service
public class MyService
{
private readonly DatabaseSettings _settings;
public MyService(IOptions<DatabaseSettings> options)
{
_settings = options.Value;
}
}
var connectionString = configuration["Database:ConnectionString"];
var apiEndpoint = configuration["Api:Endpoint"];
var awsSettings = configuration.GetSettings<AwsSettings>();
Enable logging to see what configuration is being loaded:
using Microsoft.Extensions.Logging;
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddConsole();
});
var logger = loggerFactory.CreateLogger("AwsSettings");
var host = Host.CreateDefaultBuilder(args)
.AddAwsSettings(logger)
.Build();
Here's a complete example combining multiple AWS configuration sources:
{
"AwsSettings": {
"ReloadAfter": "00:10:00",
"ParameterStore": {
"Paths": ["/myapp/prod"],
"Keys": [
{
"Path": "/aws/reference/secretsmanager/db-connection",
"Alias": "Database:ConnectionString"
}
]
},
"SecretsManager": {
"LoadAll": false,
"AcceptedSecretArns": [
"arn:aws:secretsmanager:us-east-1:123456789012:secret:api-keys"
]
},
"AppConfig": {
"ApplicationIdentifier": "myapp",
"ConfigurationProfiles": [
{
"Identifier": "application-config"
},
{
"Identifier": "feature-flags"
}
]
}
}
}
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
var host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, config) =>
{
config.AddJsonFile("appsettings.json");
config.AddAwsSettings(context.HostingEnvironment.EnvironmentName);
})
.ConfigureServices((context, services) =>
{
// Configure your services using the loaded configuration
services.Configure<DatabaseSettings>(
context.Configuration.GetSection("Database")
);
services.Configure<ApiSettings>(
context.Configuration.GetSection("Api")
);
})
.Build();
await host.RunAsync();
Ensure your application has the necessary AWS IAM permissions:
{
"Effect": "Allow",
"Action": [
"ssm:GetParameter",
"ssm:GetParameters",
"ssm:GetParametersByPath"
],
"Resource": "arn:aws:ssm:*:*:parameter/myapp/*"
}
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue",
"secretsmanager:ListSecrets"
],
"Resource": "arn:aws:secretsmanager:*:*:secret:*"
}
{
"Effect": "Allow",
"Action": [
"appconfig:GetConfiguration",
"appconfig:StartConfigurationSession"
],
"Resource": "*"
}
ReloadAfter intervals for configuration that changes/myapp/prod/... and /myapp/dev/...Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source. Please check the repository for license details.
An opinionated .NET Standard 2.0 library that provides support for all AWS settings options including Parameter Store, Secrets Manager, AppConfig Freeform and AppConfig Feature Flags.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.