Read Parameters from AWS SMM in .Net Core 3 Application
Contents
Since Amazon and Microsoft are competitors in cloud providers market, there are always nuances when you try to integrate pieces from different tech stacks. Let’s dive into how to read AWS SMM parameters in .Net Core 3 application.
Our application will read database settings from AWS Parameter store. For that you would need a POCO class:
| |
To make this sample more production ready let’s assume that you have micro-service platform “sample-platform” and .Net Core service with the name “account-service”.
Setup
For production configuration, you would need some generic settings scripts/env-development.json:
| |
And there are some account service-specific settings scripts/env-account-service-development.json:
| |
Lets store those settings to AWS with chamber. If you are don’t use chamber before please read Organize and Manage AWS Parameter Store for reference.
| |
Ok, now you are ready to configure our .Net Core application.
Configure .Net Core 3 application
To access the AWS Parameter Store, you need to install Amazon.Extensions.Configuration.SystemsManager NuGet package to your project:
| |
Then in CreateHostBuilder you need to add ConfigureAppConfiguration to build configuration with the following steps:
Define some service environment variables:
| |
Load the appsettings and environment variables:
| |
Configure access to the AWS:
| |
AWS Parameters processing in .Net Core 3 application
AWS Parameter consist treats full parameter path as:
- Path: /part-1/part-2/part-3/
- Name: param-1
Name can’t contain the symbol ‘/'. In either case, it would be a part of the path. And name can’t contain symbol ‘:’ which is by default separator for .Net Core configuration. Hence, you need to replace ‘:’ with ‘–', that you already did for all imported parameters names.
Now you need to process them before loading to configuration. For that, you would need to implement IParameterProcessor from Amazon.Extensions.Configuration.SystemsManager NuGet package.
| |
Now you can return to the ConfigureAppConfiguration and create the parameter processor.
| |
Load platform generic parameters:
| |
Load service specific parameters:
| |
Complete solutution
The final sample repository can be found here: aws-parameter-store-sample.

Hi! Thanks for the great article. I'm trying to do something similar. I have a json string as parameter value in param store, but when I try to fetch the value, I cannot get it as key-value pair. I am getting it as a string an need to deserialize it later in my code.
Is there any configuration way in which I can get value as json?
I see you have json value too, not sure how is it getting bound to your DatabaseSettings model.
Thanks again:-)
Hi Rushikesh,
AWS ParameterProcessor returns value as string.
string GetValue(Parameter parameter, string path)Unfortunately it's not possible to deserialise parameters automatically, you have to process them manually later on.
As workaround, you can create an service which receive
IOptions<DatabaseSettingsAsJsonString>as argument for constructor. And provides method which returns deserialised settingsDatabaseSettings.That looks plausible. Just another question, where do you invoke DatabaseSettingsProvider. GetDatabaseSettings() method?
Aforementioned pice of code is not complete solution.
To complete it you need to create interface
IDatabaseSettingsProvider fromDatabaseSettingsProvider `.Then you need to register service.
And inject it into the required pice of code.
Checkout more in microsoft documentation: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-3.0