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”.
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:
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
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:
The final sample repository can be found here: aws-parameter-store-sample.