Skip to content

Configuring AWS SDK in ASP.NET Core

Sponsor: Do you build complex software systems? See how NServiceBus makes it easier to design, build, and manage software systems that use message queues to achieve loose coupling. Get started for free.

Learn more about Software Architecture & Design.
Join thousands of developers getting weekly updates to increase your understanding of software architecture and design concepts.


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:

Learn more about Software Architecture & Design.
Join thousands of developers getting weekly updates to increase your understanding of software architecture and design concepts.


Leave a Reply

Your email address will not be published. Required fields are marked *