Code changes

Add Amazon.Extensions.Configuration.SystemsManager Nuget package to the following 3 projects:

  • WebUI
  • Persistence
  • Infrastructure

SSM Nuget

Update WebUI project

Then you need to enable this new configuration provider in your code.

For an ASP.NET Core application, you can do this in the Program.cs file and edit the creation of the WebHost to call ConfigureAppConfiguration to add configuration providers.

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration((hostingContext, config) =>
                {
                    ........
                    
                    config.AddSystemsManager("/Northwind");

                    config.AddEnvironmentVariables();

                    ........
                })
                .UseStartup<Startup>();

The line config.AddSystemsManager("/Northwind"); adds all of the parameters from the AWS Systems Manager Parameter Store starting with /Northwind prefix, which includes the database connection string you have created earlier, into the .NET Core configuration system.

Update Persistence project

Update Create method in DesignTimeDbContextFactoryBase.cs file to include .AddSystemsManager("/Northwind"):

private TContext Create(string basePath, string environmentName)
{
    var configuration = new ConfigurationBuilder()
        ........

        .AddSystemsManager("/Northwind")
        .Build();

    ........
}

Update Infrastructure project

Update Create method in DesignTimeDbContextFactoryBase.cs file to include .AddSystemsManager("/Northwind"):

private TContext Create(string basePath, string environmentName)
{
    var configuration = new ConfigurationBuilder()
        ........

        .AddSystemsManager("/Northwind")
        .Build();

    ........
}

Update appsettings.json

Now you can remove ConnectionStrings section from the appsettings.json file.

So it looks like this:

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "IdentityServer": {
    "Clients": {
      "Northwind.WebUI": {
        "Profile": "IdentityServerSPA"
      }
    }
  },
  "AllowedHosts": "*"
}

Run the project and verify that it works as before, connecting to the Amazon RDS SQL Server database. But this time connection string is securely stored in AWS Systems Manager Parameter Store.