localstack-dotnet / localstack-dotnet-client

A lightweight .NET client for LocalStack
MIT License
113 stars 5 forks source link
aws-sdk client-library dotnet dotnet-core localstack

LocalStack .NET Client Nuget NuGet Space Metric

LocalStack

Localstack.NET is an easy-to-use .NET client for LocalStack, a fully functional local AWS cloud stack. The client library provides a thin wrapper around aws-sdk-net which automatically configures the target endpoints to use LocalStack for your local cloud application development.

Package Stable Nightly
LocalStack.Client NuGet MyGet
LocalStack.Client.Extensions NuGet MyGet

Continuous Integration

Build server Platform Build status
Github Actions Ubuntu build-ubuntu
Github Actions Windows build-windows
Github Actions macOS build-macos

Table of Contents

  1. Supported Platforms
  2. Why LocalStack.NET Client?
  3. Prerequisites
  4. Getting Started
  5. Known Issues
  6. Developing
  7. Changelog
  8. License

Supported Platforms

Why LocalStack.NET Client?

Prerequisites

To utilize this library, you need to have LocalStack running. While LocalStack can be installed directly on your machine and accessed via the localstack cli, the recommended approach is to run LocalStack using Docker or docker-compose.

For detailed installation and setup instructions, please refer to the official LocalStack installation guide.

Getting Started

LocalStack.NET is installed from NuGet. To work with LocalStack in your .NET applications, you'll need the main library and its extensions. Here's how you can install them:

dotnet add package LocalStack.Client
dotnet add package LocalStack.Client.Extensions

Refer to documentation for more information on how to install LocalStack.NET.

LocalStack.NET is a library that provides a wrapper around the aws-sdk-net. This means you can use it in a similar way to the AWS SDK for .NET and to AWSSDK.Extensions.NETCore.Setup with a few differences. For more on how to use the AWS SDK for .NET, see Getting Started with the AWS SDK for .NET.

Setup

Here's a basic example of how to setup LocalStack.NET:

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

    services.AddLocalStack(Configuration)
    services.AddDefaultAWSOptions(Configuration.GetAWSOptions());
    services.AddAwsService<IAmazonS3>();
    services.AddAwsService<IAmazonDynamoDB>();
}

The AddLocalStack method integrates LocalStack.NET into your application, and the AddAwsService method allows you to specify which AWS services you want to use with LocalStack.

(Alternatively, `AddAWSServiceLocalStack` method can be used to prevent mix-up with `AddAWSService`.)

AddLocalStack extension method is responsible for both configurations and adding of LocalStack.Client dependencies to service collection.

Configuration

To configure LocalStack.NET, you can use entries in the appsettings.json files. Here's a basic example for different environments:

appsettings.Development.json

"LocalStack": {
    "UseLocalStack": true,
    "Session": {
        "RegionName": "eu-central-1"
    },
    "Config": {
        "LocalStackHost": "localhost.localstack.cloud", // or "localhost",
        "EdgePort": 4566
    }
}

appsettings.Production.json

"LocalStack": {
    "UseLocalStack": false
},
"AWS": {
    "Profile": "<your aws profile>",
    "Region": "eu-central-1"
}

The RegionName is important as LocalStack creates resources based on the specified region. For more advanced configurations and understanding how LocalStack.NET operates with LocalStack, refer to documentation.

Known Issues

Environment.SetEnvironmentVariable("AWS_SERVICE_URL", string.Empty);

Developing

We appreciate contributions in the form of feedback, bug reports, and pull requests.

Building the Project

To build the project, use the following commands based on your operating system:

Windows

build.ps1

Linux

./build.sh

Sandbox Applications

The LocalStack .NET repository includes several sandbox console applications located in tests/sandboxes. These applications serve both as testing tools and as examples. Refer to the documentation for more information

Running Tests

To execute the tests, use the commands below:

Windows

build.ps1 --target=tests

Linux

./build.sh --target=tests

Changelog

Please refer to CHANGELOG.md to see the complete list of changes for each release.

License

Licensed under MIT, see LICENSE for the full text.