AWS AppConfig is a capability of AWS Systems Manager, to create, manage, and quickly deploy application configurations. You can store application configurations per environment and maitain versioned copies. This extension will help you to add those values to dotnet configuration object.
- Amazon.Extensions.Configuration.AppConfig
- samples
- Amazon.Extensions.Configuration.AppConfig.Tests
- Microsoft.Extensions.Configuration
- AWSSDK.AppConfig
- System.Text.Json
- Moq
- xunit
- Microsoft.NET.Test.Sdk
- xunit.runner.visualstudio
- coverlet.collector
Step 1: Create application in AppConfig. Provide name as "AppConfigDemo". Create environment under project named as "Development". Create configuration iwth name, "queueConfigurationProfile".
Provide value of configuration as below.
{ Kafka: { "BootstrapServers": "localhost", "Producer": { "ClientId": "19", "StatisticsIntervalMs": 5000, "MessageTimeoutMs": 10000, "SocketTimeoutMs": 10000, "ApiVersionRequestTimeoutMs": 10000, "MetadataRequestTimeoutMs": 5000, "RequestTimeoutMs": 5000 }, "Consumer": { "GroupId": "49", "EnableAutoCommit": true, "StatisticsIntervalMs": 5000, "SessionTimeoutMs": 10000 } },
RabbitMQ : { "Uri": "localhost", "UserName": "root@3", "Password": "SWAMI", "DispatchConsumersAsync": true } }
Step 2: Add reference of Amazon.Extensions.Configuration.AppConfig project. Add extesion in using following code in Program.cs
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config
.AddAWSAppConfigConfiguration("AppConfigDemo",
Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"),
"queueConfigurationProfile",
new Guid().ToString());
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
Step 3: Access configuration in code.
Startup.cs - Options pattern
services.Configure<KafkaConfig>(Configuration.GetSection("Kafka"));
services.Configure<RabbitMQConfig>(Configuration.GetSection("RabbitMQ"));