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 AWS 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
- Log-in to the AWS Management Console
- 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.
- Create C# console or Web application
- Reference the AWS SDK SimpleSystemsManager Package using nuget package console
<PackageReference Include="AWSSDK.SimpleSystemsManagement" Version="3.5.5.6" />
- Add the below Assembly references
using Amazon.SimpleSystemsManagement; using Amazon.SimpleSystemsManagement.Model;
var request = new GetParameterRequest()
{
Name = "/CleanArchitectureAppWebApi/postgresconnection"
};
using (var client = new AmazonSimpleSystemsManagementClient(Amazon.RegionEndpoint.GetBySystemName("ap-south-1")))
{
var response = client.GetParameterAsync(request).GetAwaiter().GetResult();
connectionString = response.Parameter.Value;
}
The Name
and the Region
can be read from the appsettings.json configuration.
You can see the implementation in the below Github project
sunilkumarmedium / CleanArchitectureApp
Clean Architecture Application Design from Scratch using Dotnet Core 5 WebApi and Angular 11 FrontEnd
CleanArchitectureApp
Clean Architecture Application Design from Scratch using Dotnet Core 5 WebApi and Angular 11 FrontEnd
Technologies
- ASP.NET Core 5
- NHibernate
- Angular 11
- Angular CLI 11
- Clean Architecture
- Swashbuckle.AspNetCore.Swagger
- Design Pattern: Command Query Responsibility Segregation (CQRS)
- Fluent Validation
- WebAPI Global Exception Middleware
- Login, Logout and Forgot Password using JWT tokens
- Microsoft Sql Server and Postgresql supported
- AWS Postgres RDS
- AWS Lambda
- AWS Systems Manager
- AWS Simple Storage Service (S3)
- Docker
Pre-requisites
- .Net core 5 SDK
- Visual studio 2019 OR VSCode with C# extension
- NodeJs (Latest LTS)
- Microsoft SQL Server (Optional: If MS SQL server required instead of Sqlite during development)
- POSTGRESQL
Configuration
- Clone the repo: git clone https://github.com/sunilkumarmedium/CleanArchitectureApp.git
- Execute the sql scripts available in the folder
/sql/
- MSSQL use CleanArchitectureDB.sql
- POSTGRES use CleanArchitectureDB-Postgres
- Change the database connectionstring in appsettings.json
- Path : CleanArchitectureApp.WebApi/appsettings.Development.json or appsettings.json
-
"DBProvider": "MSSQL" ,
UseMSSQL
to connect to Microsoft SqlServer OrPOSTGRES
to connect to PostgreSQL…
Happy Coding!
Top comments (0)