Showing posts with label AWS. Show all posts
Showing posts with label AWS. Show all posts

Sunday, 1 September 2019

Working with AWS Parameter Store in .NET

Using from code

Before starting, I installed the AWS CLI. When trying to figure out how to pass credentials into the AWS SDK, I stumbled upon the SDK's local credential discovery chain.

Among other options, the SDK automatically checks for local configuration files created in your user directory when you run aws configure via the CLI. It handles authentication seamlessly behind the scenes—a handy trick for local development!

Setting Up the Project & Package

I created a new ASP.NET Core MVC project and added the official AWS configuration package via NuGet:


Then I created a simple “Settings” class that holds the configuration values we’ll get back from AWS.
public class Settings
{
   public string awsvalue { get; set; }
   public string awsvalue2 { get; set; }
}
In the appsettings.json file, I told my app which AWS region to use.
{
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*",
  "AWS": {
    "Profile": "default",
    "Region": "us-west-2"
  }
}
In Program.cs, I updated the web host builder to hook into Systems Manager as a configuration provider. Here, I'm pulling all settings stored under the /seroterdemo path:
public class Program
{
  public static void Main(string[] args)
  {
     CreateWebHostBuilder(args).Build().Run();
  }

  public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
     WebHost.CreateDefaultBuilder(args)
       .ConfigureAppConfiguration(builder =>
       {
          builder.AddSystemsManager("/seroterdemo");
       })
       .UseStartup<Startup>();
    }

Binding and Accessing Options

To make these values available to the application, I bound the configuration section to my Settings POCO in Startup.cs:

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<Settings>(Configuration.GetSection("properties"));

    services.Configure<CookiePolicyOptions>(options =>
    {
       options.CheckConsentNeeded = context => true;
       options.MinimumSameSitePolicy = SameSiteMode.None;
     });
}
Finally, I injected IOptionsSnapshot<Settings> into the controller constructor. Using IOptionsSnapshot ensures that when the background reload timer fetches updated parameters from AWS, the controller automatically picks up the latest values on the next request!
        private readonly Settings _settings;

        public HomeController(IOptions<Settings> settings)
        {
            _settings = settings.Value;
        }

        public IActionResult Index()
        {
            ViewData["configval"] = _settings.awsvalue;
            ViewData["configval2"] = _settings.awsvalue2;

            return View();
        }
After updating my View to render the two properties, I launched the application—and both values stored in Parameter Store populated as expected.

What I Like About Parameter Store

  • Unbeatable Price: Standard parameters are free (up to 10,000 per account), which makes it a no-brainer for basic configuration and string parameters.

  • Full Audit Trail: Every update increments the version number and records an explicit change history showing who changed what and when.

  • Native .NET Core Integration: AWS’s Amazon.Extensions.Configuration.SystemsManager package integrates seamlessly into ASP.NET Core’s native IConfigurationBuilder, complete with automatic background reloads using TimeSpan.

The AWS team built this extension for .NET Core, and they added capabilities for reloading parameters automatically. Nice touch!

Friday, 30 August 2019

Quick Look: AWS Parameter store

AWS offers a parameter store as part of the AWS Systems Manager service. Parameter Store serves a more fundamental purpose: a central, secure key-value store for application configuration and secrets.
Getting started is simple. Navigate to the AWS Console, open AWS Systems Manager, and select Parameter Store from the left navigation panel. The interface allows you to view, edit, delete, and create parameters—supporting three data types: String, StringList, and encrypted SecureString (backed by AWS Key Management Service).
Each parameter gets a name and value. For the name, I used a “/” to define a hierarchy. The parameter type can be a string, list of strings, or encrypted string.
The UI was smart enough that when I went to go add a second parameter (/seroterdemo/properties/awsvalue2), it detected my existing hierarchy.
And that's it!! Now you are ready to use it in a .NET Core web app.


And lastly , some Real-World Usage Patterns

While it remains a lightweight way to store static variables, modern cloud architectures rely on Parameter Store for critical integrations:

  • Infrastructure as Code (IaC): AWS CloudFormation, Terraform, and AWS CDK directly resolve Parameter Store values at deployment time using dynamic references.

  • Container & Serverless Injection: ECS task definitions and AWS Lambda functions natively fetch Parameter Store values as runtime environment variables, separating application logic from secrets and config.