Tag: NETCore


General Availability for .NET Core Support in the AWS SDK for .NET

by Norm Johanson | on | in .NET | Permalink | Comments |  Share

Today, we announce the general availability (GA) of our .NET Core support in the AWS SDK for .NET. Previously, we’ve supported .NET Core in our 3.2.x beta NuGet packages while maintaining our 3.1.x NuGet packages on our stable master branch with the frequent AWS service updates.

With the move to GA status for .NET Core, we’ve merged .NET Core support into the stable master branch and, going forward, will release version 3.3.x NuGet packages for the AWS SDK for .NET. We’ll add AWS service updates to our .NET Core version at the same time we add them to the rest of the .NET platforms we support, like .NET Framework 3.5 and 4.5. The SDK’s change of status also means our AWS Tools for PowerShell Core module (AWSPowerShell.NetCore) is at GA status, and its version bumps to 3.3.x to match the underlying SDK version.

This release is one more step in our continuing support for .NET Core on AWS. Other exciting .NET Core releases we’ve had this year include:

For help setting up and configuring the SDK for use with .NET Core, see our previous post on some of the extensions we added to take advantage of the new .NET Core frameworks.

We welcome your feedback. Check out our GitHub repository and let us know what you think of our .NET and .NET Core support.

Configuring AWS SDK with .NET Core

by Norm Johanson | on | in .NET | Permalink | Comments |  Share

One of the biggest changes in .NET Core is the removal of ConfigurationManager and the standard app.config and web.config files that were used ubiquitously with .NET Framework and ASP.NET applications. The AWS SDK for .NET used this configuration system to set things like AWS credentials and region so that you wouldn’t have to do this in code.

A new configuration system in .NET Core allows any type of input source from any location. Also, the configuration object isn’t a global singleton like the old ConfigurationManager was, so the AWS SDK for .NET doesn’t have access to read settings from it.

To make it easy to use the AWS SDK for .NET with .NET Core, we have released a new NuGet package called AWSSDK.Extensions.NETCore.Setup. Like many .NET Core libraries, it adds extension methods to the IConfiguration interface to make getting the AWS configuration seamless.

Using AWSSDK.Extensions.NETCore.Setup

If we create an ASP.NET Core MVC application in Visual Studio, the constructor for Startup.cs handles configuration by reading in various input sources, using the ConfigurationBuilder and setting the Configuration property to the built IConfiguration object.

public Startup(IHostingEnvironment env)
{
    var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
        .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
        .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
        .AddEnvironmentVariables();
    Configuration = builder.Build();
}

To use the Configuration object to get the AWS options, we first add the AWSSDK.Extensions.NETCore.Setup NuGet package. Then, we add our options to the configuration file. Notice one of the files added to the ConfigurationBuilder is called $"appsettings.{env.EnvironmentName}.json". If you look at the Debug tab in the project’s properties, you can see this file is set to Development. This works great for local testing because we can put our configuration in the appsettings.Development.json file, which is loaded only during local testing in Visual Studio. When we deploy to an Amazon EC2 instance the EnvironmentName will default to Production and this file will be ignored causing the AWS SDK for .NET to fall back to the IAM credentials and region configured for the EC2 instance.

Let’s add an appsettings.Development.json file to our project and supply our AWS settings.

{
  "AWS": {
    "Profile": "local-test-profile",
    "Region": "us-west-2"
  }
}

To get the AWS options set in the file, we call the extension method that is added to IConfiguration, GetAWSOptions. To construct a service client from these options, we call CreateServiceClient. The following example code shows how to create an S3 service client.

var options = Configuration.GetAWSOptions();
IAmazonS3 client = options.CreateServiceClient();

ASP.NET Core Dependency Injection

The AWSSDK.Extensions.NETCore.Setup NuGet package also integrates with a new dependency injection system in ASP.NET Core. The ConfigureServices method in Startup is where the MVC services are added. If the application is using Entity Framework, this is also where that is initialized.

public void ConfigureServices(IServiceCollection services)
{
    // Add framework services.
    services.AddMvc();
}

The AWSSDK.Extensions.NETCore.Setup NuGet package adds new extension methods to IServiceCollection that you can use to add AWS services to the dependency injection. The following code shows how we add the AWS options read from IConfiguration and add S3 and Amazon DynamoDB to our list of services.

public void ConfigureServices(IServiceCollection services)
{
    // Add framework services.
    services.AddMvc();
    services.AddDefaultAWSOptions(Configuration.GetAWSOptions());
    services.AddAWSService<IAmazonS3>();
    services.AddAWSService<IAmazonDynamoDB>();
}

Now, if our MVC controllers use either IAmazonS3 or IAmazonDynamoDB as parameters in their constructors, the dependency injection system passes those services in.

public class HomeController : Controller
{
    IAmazonS3 S3Client { get; set; }

    public HomeController(IAmazonS3 s3Client)
    {
        this.S3Client = s3Client;
    }

    ...

}

Summary

We hope this new AWSSDK.Extensions.NETCore.Setup NuGet package helps you get started with ASP.NET Core and AWS. Feel free to give us your feedback at our GitHub repository for the AWS SDK for .NET

AWS SDK for .NET Status Update for .NET Core Support

by Norm Johanson | on | in .NET | Permalink | Comments |  Share

The AWS SDK for .NET has included support for the .NET Core platform in our NuGet 3.2 beta packages since last September. With our recent push of version 3.2.6-beta to NuGet, we’ve switched from netstandard 1.5 to 1.3 to increase the SDK’s compatibility with other libraries. This version also includes many of the high-level abstractions and utility methods that were previously only available on the 3.5 and 4.5 .NET Framework versions of the SDK.

After some final testing and performance optimization, we will move our .NET Core support out of beta and into our master branch. (We’re currently investigating differences in the way HTTP connections are handled between .NET Framework and .NET Core.) At that point, we will bump the version number of all NuGet packages for the SDK to 3.3. Then .NET Core support for future service updates will be provided with the regular .NET Framework version of the SDK.

Now is a great time to give us feedback on our .NET Core support. Feel free to use the 3.2 beta versions of the SDK from NuGet and leave your feedback on our GitHub repository.