Using AWS Parameter Store for .NET Core Configuration

Parameter Store for .NET Core

One of the aspects I love about .NET Core is the new configuration and options pattern. In a continuation from my last post on using AWS Parameter Store for Data Protection keys, you can imagine it is possible to use Parameter Store for .NET Core Configuration.

Amazon.Extensions.Configuration.SystemsManager

There is a package by AWS that facilitates making using Parameter Store incredibly easy. Simply add the Amazon.Extensions.Configuration.SystemsManager package to your project and use the AddSystemsManager extension method on IConfigurationBuilder

The argument you pass to AddSystemsManager will be the prefix to your configuration hierarchy within Parameter Store. In my example, I’m using /Demo as my prefix, as you will also see below.

If you look at the first two entries, I can now create classes that match this hierarchy.

Configure

Next step is to add this configuration via the IServiceCollection using the Configure<T> method. Where T is our configuration type DemoConfig

This will add registration for the type IOptions<DemoConfig> so we can inject it in our Controllers or anywhere else the ServiceProvider is used.

This results in our config variable being set to the values from Parameter Store.

Parameter Store for .NET Core

If you have any questions or comments, please let me know on twitter as I will focus my posts on those questions and comments.

Related Links:

Enjoy this post? Subscribe!

Subscribe to our weekly Newsletter and stay tuned.

Configuring AWS SDK in ASP.NET Core

Configuring AWS SDK in ASP.NET Core

If you’re using any AWS Services, you’re likely going to be using the AWS SDK via NuGet packages. You don’t need to configure anything to start using the SDK, but there are a few things that can make your life a lot easier. Follow along for a how-to on configuring AWS SDK in ASP.NET Core.

AWS CLI Named Profiles

The AWS Command Line Interface (CLI) is the first thing you’re going to want to have. Beyond controlling AWS services it allows you to configure credential profiles.

Once you have the CLI installed, to configure the default profile simply run and follow the prompt to enter your access key, secret and region.

> aws configure

For the rest of this example, I’m going to be using the default profile that I’ve configured that contains my access key and secret.

AppSettings

The AWS SDK will look for an AWS key in your appsettings.json file. It will use this section for configuration. In this section, you can define which Profile to use as well as many other options including as Region.

Environment Variables

You can also use Environment Variables to define these same settings. Be sure to use colon as hierarchy.

Startup.cs

The AWSSDK.Extensions.NETCore.Setup NuGet package that adds extension methods to IConfiguration and IServiceCollection that makes it simple to retrieve AWS configuration and types.

Now if you inject the IAmazonS3 from a Controller or even if you resolve it from context.RequestServices.GetService<IAmazonS3>() you will get out an instance that is auto-configured with the access key and secret from your Default profile as well as the Region defined in your appsetting or Environment Variable.

AWS SDK in ASP.NET Core

That’s the quick start way of being able to use the AWS SDK without having to specify any of your credentials in your source as well as being able to use dependency injection to have the AWS SDK types resolve pre-configured.

If you have any questions or comments, please let me know on twitter as I will focus my posts on those questions and comments.

Related Links:

Enjoy this post? Subscribe!

Subscribe to our weekly Newsletter and stay tuned.

Practical ASP.NET Core SignalR: Azure SignalR Service

ASP.NET Core SignalR Scaling

In this section, I’m going to cover how to deal with scaling SignalR by using the Azure SignalR Service. This is a managed service that is an alternative to using the Redis backplane that I’ve described in the previous section.

You may want to use this option as it eliminates having to manage your own Redis instance as well as dealing with a load balancers configuration of sticky sessions (client affinity). Everything is all pre-configured for you, and is a fully managed service.

This blog post is apart of a course that is a complete step-by-setup guide on how to build real-time web applications using ASP.NET Core SignalR. By the end of this course, you’ll be able to build real-world, scalable, production applications using the tools and techniques provided in this course.

If you haven’t already, check out the prior sections of this course.

  1. Course Overview
  2. ASP.NET Core SignalR Overview
  3. Basics
  4. Server Hubs
  5. HubContext
  6. Authorization
  7. Scaling with Redis

SignalR Scaling

I’ve covered the basics of scaling in the previous section and how having a web farm poses problems when using SignalR.

If you haven’t already or are need an overview of a webfarm scenario with SignalR, check out that section which covers how to scale using Redis as a backplane.

Azure SignalR Service

First thing to do is add a new resource in Azure by and search for the SignalR Service.

As you are creating the new service, when selecting the pricing tier, note that the free tier does not support changing the unit count. Meaning you are limited to 20 connections and 20k messages/day. The standard tier gives you 1k connections per unit and 1M messages/day/unit and allows you to scale up to 100 units (depending on the region).

Once created, go to the Settings > Keys page where you will need to copy the Connection String

Configuration

First, you’ll need to reference the Microsoft.Azure.SignalR package in your csproj.

From here you simply need to change the ConfigureServices() to use AddAzureSignalR() and modify the Configure() to call UseAzureSignalR()

User Secrets

Now we need to place our Azure SignalR Service connection string in user secrets. To add to our secrets via the dotnet CLI:

dotnet user-secrets set Azure:SignalR:ConnectionString "Connection String Goes Here"   

If you’re unfamiliar with user secrets, check out my blog post on handling sensitive configuration data.

That’s it. You’ll now be using the Azure SignalR Service and be able to scale to 1000’s of connections.

Get The Course!

You’ve got several options:

  1. Check out my Practical ASP.NET Core SignalR playlist on my CodeOpinion YouTube channel.
  2. Access the full course now by enrolling for free on Teachable.
  3. Follow along with the blog post series here on CodeOpinion.com
    1. Course Overview
    2. ASP.NET Core SignalR Overview
    3. Basics
    4. Server Hubs
    5. HubContext
    6. Authorization
    7. Scaling with Redis
    8. Scaling with Azure SignalR Service

Source Code

All of the source code for this blog post and this course is available the Practical.AspNetCore.SignalR repo on GitHub.