Create ASP.NET Core project

Create new ASP.NET Core Web Application.

Create project

Create project

  • Choose API project template.
  • Choose ASP.NET Core 3.1.
  • Disable Docker support

Create project

Once project is created, add Amazon.Extensions.Configuration.SystemsManager Nuget package to the project.

Nuget

Next you need to enable new configuration provider in the code.

For an ASP.NET Core application, you can do this in the Program.cs file by adding ConfigureAppConfiguration method:

public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureAppConfiguration(config =>
            {
                config.AddSystemsManager("/SampleApp");
            })
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });

Update code for WeatherForecastController.cs to read connection string from the configuration.

Add the following using statement:

using Microsoft.Extensions.Configuration;

Inject IConfiguration to the constructor:

private readonly IConfiguration _configuration;

public WeatherForecastController(ILogger<WeatherForecastController> logger, IConfiguration configuration)
{
    _logger = logger;
    _configuration = configuration;
}

Add new method to read connection string:

// GET api/weatherforecast/connection
[HttpGet]
[Route("connection")]
public ActionResult<string> GetConnectionString()
{
    var connectionString = _configuration.GetConnectionString("MyConnection");

    return connectionString;
}

Run the project and verify that connection string is displayed in decrypted form.

Test

Congratulations! You have successfully configured AWS Systems Manager configuration source provider and retrieved parameter from the parameter store using standard IConfiguration interface.