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.
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
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.
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.
You can also use Environment Variables to define these same settings. Be sure to use colon as hierarchy.
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.