Configuring Parameter Store - AWS Prescriptive Guidance

Configuring Parameter Store

Parameter Store is a capability of AWS Secrets Manager. It provides secure, hierarchical storage for configuration data management and secrets management. You can store data such as passwords, database strings, Amazon Machine Image (AMI) IDs, and license codes as parameter values.

Prerequisites for using Parameter Store with .NET Framework applications

Example

To retrieve values from Parameter Store in the ASP.NET Core web applications or API:

  1. Add the following NuGet package to the ASP.NET Core web API.

    Amazon.Extensions.Configuration.SystemsManager
  2. In the Program.cs file, make the following changes.

    • Add using statements (1).

      using Amazon; using Amazon.Extensions.NETCore.Setup;
    • Add the AWS Systems Manager configuration (2).

      builder.Configuration.AddSystemsManager("/dev/myapp", new AWSOptions { Region = RegionEndpoint.EUWest2 });
    Changes to Program.cs file for accessing Parameter Store
    Note

    You should call the /myapp/dev and RegionEndPoint parameters dynamically or from the environment variables (Region = RegionEndpoint.GetBySystemName("eu-west-2")). Do not hardcode these values in production environments.

  3. Create a new class file and name it ParameterOptions.cs. Open the file and add the following code.

    public class ParameterOptions { public const string ParameterName = "Tenant"; public string key1 { get; set; } = string.Empty; public string key2 { get; set; } = string.Empty; }
  4. To retrieve the values from Parameter Store, make the following changes to the controller class file (for example, ValuesController.cs).

    • Add the constructor (1).

      private readonly IConfiguration _configuration; public ParametersController(IConfiguration configuration) { _configuration = configuration; }
    • Retrieve the values from Parameter Store (2).

      var parameterOptions = new ParameterOptions(); _configuration.GetSection(ParameterOptions.ParameterName).Bind(parameterOptions); return new string[] { parameterOptions.key1, parameterOptions.key2 };
    Changes to the controller class file for retrieving values from Parameter Store

Resources