.Net Programming

Explore the .Net with the latest in C# from basic to advanced, including .Net versions 9, 8, 6, 5…

Follow publication

AWS Systems Manager Parameter Store for Managing Configuration and Retrieve at Runtime using C#

Introduction

One common challenge in application development is ensuring that any configuration data liable to change across deployments is separated from the code, allowing a single release to be configured for multiple environments.

AWS’s solution for storing configuration data is called AWS Systems Manager Parameter Store.

Parameter Store provides a mechanism to store and manage configuration data, encrypted or plain text, using a hierarchical structure.

Parameter Store is ideal for storing passwords, database strings, and all other types of general configuration values.

Pre-requisites
To complete this learning, you will need:
✓ An AWS Account
✓ An IAM user with access key credentials
✓ Visual Studio Code or Visual Studio 2019+ for Windows

If you don’t have an account visit https://aws.amazon.com and click Sign Up.

You must have a set of valid AWS credentials, consisting of an access key and a secret key, which are used to sign programmatic requests to AWS. You can obtain a set of account credentials when you create your account, although we recommend you do not use these credentials and instead create an IAM user and use those credentials.

Installing the AWS CLI:

Install the `AWS CLI` for Windows, Mac, or Linux: https://aws.amazon.com/cli/

Once installed, you can configure the CLI by running the `aws configure` command in a terminal or command-line window.

When prompted, enter your `AWS Access Key ID` and press Enter.

Enter your `AWS Secret Access Key` when prompted and then press Enter.

For the `default region name` you should enter your chosen region code (e.g. ap-south-1)

Finally, for the `default output` format you can just press Enter.

Creating Parameter Store data using AWS CLI

To create an entry in the Parameter Store, execute the following command in the terminal or command-line window:

aws ssm put-parameter — name “/CleanArchitectureAppWebApi/postgresconnection” — type String — value “ConnectionString”

Adding Secure String

aws ssm put-parameter — name “secure-parameter-name” — type “SecureString” — value “secure-parameter-value”

The above command will create the parameter in the region you specified as your default profile configured.
To create a parameter in a different region, add the — region parameter, for example — region ap-south-1.

We can retrieve the parameter created by running the following command in the terminal or command-line window:

aws ssm get-parameter — name “/CleanArchitectureAppWebApi/postgresconnection”

To delete data from Parameter Store execute the following command in a terminal or command-line window:

aws ssm delete-parameter — name “/CleanArchitectureAppWebApi/postgresconnection”

Creating Parameter Store data using AWS Console

  1. Log-in to the AWS Management Console
  2. search for ‘Systems Manager’ and Click on Create Parameter

Retrieving the parameter using C#

Now that you have created a configuration value, it’s time to create a basic .NET C# application that can retrieve the data at runtime.
1. Create C# console or Web application
2. Reference the AWS SDK SimpleSystemsManager Package using nuget package console

<PackageReference Include=”AWSSDK.SimpleSystemsManagement” Version=”3.5.5.6" />

3. Add the below Assembly references

using Amazon.SimpleSystemsManagement;
using Amazon.SimpleSystemsManagement.Model;

The `Name` and the `Region` can be read from the appsettings.json configuration.

You can see the implementation in the below Github project
https://github.com/sunilkumarmedium/CleanArchitectureApp

Happy Coding!

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

.Net Programming
.Net Programming

Published in .Net Programming

Explore the .Net with the latest in C# from basic to advanced, including .Net versions 9, 8, 6, 5, Core 3.1, .Net Framework, ASP.NET Core, MVC, design patterns, OOPS, and SOLID principles. Get top tutorials, best practices, and hands-on code examples on GitHub.

Sunil Kumar
Sunil Kumar

Written by Sunil Kumar

Architect and Full Stack Developer in Dotnet Core, C#, WebApi’s, Integrations and Learner on Angular and React FrontEnd

No responses yet

Write a response