Azure  

Setting Up .NET Projects with Azure SDKs and AWS SDKs

Once you’ve chosen a cloud provider (or decided to support both), the next step is to integrate your .NET projects with cloud services. Both Microsoft Azure and Amazon Web Services (AWS) provide rich SDKs that make it easy to interact with cloud resources like storage, databases, and messaging systems directly from your C# code.

This article walks you through setting up and using the Azure SDK for .NET and the AWS SDK for .NET in a sample ASP.NET Core project.

1. Install the SDKs

Azure SDK for .NET

Azure provides NuGet packages for each service. For example:

dotnet add package Azure.Storage.Blobs
dotnet add package Azure.Identity

AWS SDK for .NET

AWS SDK is modular too, with NuGet packages per service:

dotnet add package AWSSDK.S3
dotnet add package AWSSDK.Extensions.NETCore.Setup

2. Configure Authentication

Azure Authentication

Azure SDK uses DefaultAzureCredential, which automatically picks the best available authentication method (e.g., environment variables, Visual Studio, Azure CLI, or Managed Identity).

using Azure.Identity;
using Azure.Storage.Blobs;

var blobServiceClient = new BlobServiceClient(
    new Uri("https://<your-storage-account>.blob.core.windows.net"),
    new DefaultAzureCredential());

AWS Authentication

AWS SDK uses credentials from the Shared Credentials File (~/.aws/credentials), environment variables, or IAM roles. In ASP.NET Core, register AWS services with dependency injection:

using Amazon.S3;
using Amazon.Extensions.NETCore.Setup;

var builder = WebApplication.CreateBuilder(args);

// Load AWS config from appsettings.json or environment
builder.Services.AddDefaultAWSOptions(builder.Configuration.GetAWSOptions());
builder.Services.AddAWSService<IAmazonS3>();

var app = builder.Build();

3. Example: Uploading Files to Cloud Storage

Upload to Azure Blob Storage

var containerClient = blobServiceClient.GetBlobContainerClient("my-container");
await containerClient.CreateIfNotExistsAsync();

var blobClient = containerClient.GetBlobClient("example.txt");
await blobClient.UploadAsync(new BinaryData("Hello from Azure!"), overwrite: true);

Upload to AWS S3

public class StorageService
{
    private readonly IAmazonS3 _s3Client;

    public StorageService(IAmazonS3 s3Client)
    {
        _s3Client = s3Client;
    }

    public async Task UploadFileAsync()
    {
        var request = new Amazon.S3.Model.PutObjectRequest
        {
            BucketName = "my-bucket",
            Key = "example.txt",
            ContentBody = "Hello from AWS!"
        };

        await _s3Client.PutObjectAsync(request);
    }
}

4. Using Configuration Files

Both SDKs support loading from appsettings.json. Example:

{
  "AWS": {
    "Region": "us-east-1",
    "Profile": "default"
  },
  "Azure": {
    "StorageAccountUrl": "https://<your-storage-account>.blob.core.windows.net"
  }
}

Then bind them into services with .NET’s options pattern.

5. Best Practices

  • Use Managed Identity / IAM Roles instead of storing credentials.

  • Follow least-privilege principle: only grant access to the resources needed.

  • Abstract Cloud Services behind interfaces so you can swap Azure ↔ AWS later.

  • Centralize Configuration with Azure Key Vault or AWS Secrets Manager.

  • Enable Logging with Application Insights (Azure) or CloudWatch (AWS).

Conclusion

By installing the appropriate SDKs and configuring authentication properly, you can easily integrate your .NET applications with both Azure and AWS. Whether you’re uploading files, connecting to databases, or consuming messaging systems, the SDKs provide a straightforward developer experience.