.Net CoreawsDevelopment

Amazon S3 and .NET Core.

In this blog post I will play around with Amazon AWS S3 and .NET Core 3.0. I will check how .NET Core is getting along with the most popular cloud platform.

Amazon S3.

Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance. This means customers of all sizes and industries can use it to store and protect any amount of data for a range of use cases, such as websites, mobile applications, backup and restore, archive, enterprise applications, IoT devices, and big data analytics. Amazon S3 provides easy-to-use management features so you can organize your data and configure finely-tuned access controls to meet your specific business, organizational, and compliance requirements.

See here for more!

.NET Core.

.NET Core is an open-source, general-purpose development platform maintained by Microsoft and the .NET community on GitHub. It’s cross-platform (supporting Windows, macOS, and Linux) and can be used to build device, cloud, and IoT applications.

See here for more!

Let’s start.

In my personal opinion, .NET Core is the best development stack. With .NET Core 3.0 desktop stacks (WPF and Windows Forms) will be included.

Amazon with its Web Services is the biggest cloud service provider. I already did some projects with Amazon S3 and tons of .NET-based projects. I was really eager to try, play around and see how these two technologies play along together.

Being early adopter, I needed to try .NET Core 3 Preview 7 & (latest version at the time of this writing) with Windows Forms (also new desktop development stack introduced in NET Core 3.0). I tried to check how these two technologies/frameworks play along with AWS S3.

To start with, first, I prepared everything on Amazon server-side.

AWS S3 access keys.

I log-in into my AWS Console (https://console.aws.amazon.com/console/home) and I created new access ID/Key for my test app.

For the purpose of my testing “Access Key/Secret key” credential option is fine, but using IAM user credential option is better because it provides several benefits, just to mention few: programmatic/console access, better tuning of access rules, grouping, option to MFA, auto managing of permissions, etc… As said, for the purpose of this testing I used Access Keys option.

.NET Core 3.0 & Windows Forms.

Windows Forms desktop stack and .NET Core 3.0 are still in preview (Preview 7), so I expected some problems. First, I created new .NET Core 3 (Preview 7) Windows Forms application in my Visual Studio 2019. First problem popped-up very quickly: Visual Studio 2019 Windows Forms designer was crashing. I got this error:

Visual Studio 2019 & .NET Core 3 & Win Forms designer error.

After some investigation, I found out that is known issue. I overcome this by designing Windows Forms GUI elements in parallel .NET Framework application and then just copied generated code in my .NET Code app.

After having all in place, my demo application looked similar to this:

GUI was ready, so I needed to start putting in some “logic”. First, I included some NuGet dependencies:

First two AWSDK.*** dependencies are Amazon S3 SDK packages for working with AWS S3 services. Microsoft.Extensions.Configuration.Json is package containing JSON configuration extensions. Because I really like Dependency Injection approach, I also used Microsoft.Extensions.DependencyInjection extension for that purposes.

My application entry point looked like this:

Let’s check what is going on in my application bootstrapping phase:

  1. From line 6 to 8, configuration file is processed and handled. This config file processed, contains AWS basic info, e.g.
  2. From line 10 to 13 services registration is executed.
  3. Line 16 and 17 apply default styles to Windows Forms application.
  4. Line 20 and 21 start the application.

For the purpose of this demo, my AWS S2 access credentials were put into JSON file on my local filesystem (c:\temp\profileData.txt). This file contain AWS credential information (check paragraph AWS S3 access keys).

When doing production ready code, this file/data should be safely stored in some secure storage.

I injected IAmazonS3 service into Form constructor in order to use it in my prototype. Here, I need to mention, that demo app is not perfectly designed (or better yet: has no design at all :), but skilled observer with little imagination can quickly see how this form class could be transformed into some custom AWS client service, and injected all over the application. Here, I focused only on core functionality.

I injected IAmazonS3 interface into my main form like this:

Basic AWS S3 scenarios.

Create empty bucket.

My testing application:

Result on AWS S3 storage:

Create empty bucket and upload file.

My testing application:

Result on AWS S3 storage:

Create & Delete bucket.

My testing application:

Bucket content listing

My testing application:

AWS S3 storage:

More on AWS SDK for .NET.

Amazon.S3.IAmazonS3 interface has very rich API for AWS S3. With similar approach as presented above, you can extend usage on very complex scenarios/cases.

In this blog post, I presented only AWS S3 component of AWS SDK for .NET. This SDK can also be used for other Amazon services: Amazon DynamoDB, Amazon Glacier, Batch, ElastiCache, etc…

AWS SDK for .NET is open source with Apache 2.0 license. You can check out source code at https://github.com/aws/aws-sdk-net.

Furthermore, Amazon has awesome documentation on AWS SDK for .NET: https://aws.amazon.com/sdk-for-net.

AWS SDK for .NET target multiple platforms including: Windows Store, Windows Phone, and Xamarin on iOS and Android.


Lately, I tested a lot of things with .NET Core 3.0 (different preview versions) – and amazingly almost everything I tested just worked. OK, Visual Studio has some Windows Forms designer issues, but this will fixed when .Net Core 3.0 will be released.

I would like to mentioned also that Amazon has super support for developing .NET application targeting AWS cloud services. Latest AWS SDK is very modern and feature-rich.

You can download code for this experiment here: https://github.com/josipx/Jenx.Aws.Playground

Leave a Reply

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.