All Projects → localstack-dotnet → Localstack Dotnet Client

localstack-dotnet / Localstack Dotnet Client

Licence: mit
A lightweight .NET client for LocalStack

Projects that are alternatives of or similar to Localstack Dotnet Client

Westwind.htmlpackager
A small utility class used to package HTML content into a self contained HTML document both as a single file, or a folder with all dependencies copied to local.
Stars: ✭ 27 (-32.5%)
Mutual labels:  dotnet-core
Amazon Cognito Identity Js
Amazon Cognito Identity SDK for JavaScript
Stars: ✭ 965 (+2312.5%)
Mutual labels:  aws-sdk
Maximerouiller.azure.appservice.easyauth
.NET Core integration of Azure AppService EasyAuth
Stars: ✭ 38 (-5%)
Mutual labels:  dotnet-core
Mlnet Workshop
ML.NET Workshop to predict car sales prices
Stars: ✭ 29 (-27.5%)
Mutual labels:  dotnet-core
Ably Go
Go client library SDK for Ably realtime messaging service
Stars: ✭ 29 (-27.5%)
Mutual labels:  client-library
Server
The core infrastructure backend (API, database, Docker, etc).
Stars: ✭ 8,797 (+21892.5%)
Mutual labels:  dotnet-core
Carter
Carter is framework that is a thin layer of extension methods and functionality over ASP.NET Core allowing code to be more explicit and most importantly more enjoyable.
Stars: ✭ 875 (+2087.5%)
Mutual labels:  dotnet-core
Angular Aws Amplify
Sample implementation for AWS Amplify in Angular project
Stars: ✭ 40 (+0%)
Mutual labels:  aws-sdk
Reactive Aws Clients
AWS Client libraries for Scala (Automatic generation from AWS source code)
Stars: ✭ 30 (-25%)
Mutual labels:  aws-sdk
Sqlite Global Tool
SQLite .NET Core CLI tool that allows the user to manually enter and execute SQL statements with or without showing query result.
Stars: ✭ 37 (-7.5%)
Mutual labels:  dotnet-core
Eschool
eSchool Microservice based Solution
Stars: ✭ 29 (-27.5%)
Mutual labels:  dotnet-core
Hadeslang
The Hades Programming Language
Stars: ✭ 30 (-25%)
Mutual labels:  dotnet-core
Z00bfuscator
Z00bfuscator is the simple, open-source, cross-platform obfuscator for .NET Assemblies built on .NET Core
Stars: ✭ 35 (-12.5%)
Mutual labels:  dotnet-core
Workshop Net Core Iniciantes
Repositório responsável pelo workshop para aprender os principais conceitos de desenvolvimento em .NET CORE & EF
Stars: ✭ 28 (-30%)
Mutual labels:  dotnet-core
Aws Sdk
Using vertx-client for AWS SDK v2
Stars: ✭ 38 (-5%)
Mutual labels:  aws-sdk
Aws Sdk Go
AWS SDK for the Go programming language.
Stars: ✭ 7,270 (+18075%)
Mutual labels:  aws-sdk
Standardfile
Yet Another Standardfile (standardnotes server) Implementation written in Golang
Stars: ✭ 34 (-15%)
Mutual labels:  client-library
Marten.fsharp
A set of FSharp wrappers around Marten
Stars: ✭ 40 (+0%)
Mutual labels:  dotnet-core
Asp.net Core Graphql Middleware
ASP.Net Core GraphQL Middleware
Stars: ✭ 38 (-5%)
Mutual labels:  dotnet-core
Computesharp
A .NET 5 library to run C# code in parallel on the GPU through DX12 and dynamically generated HLSL compute shaders, with the goal of making GPU computing easy to use for all .NET developers! 🚀
Stars: ✭ 982 (+2355%)
Mutual labels:  dotnet-core

Nuget NuGet

LocalStack .Net Core and .Net Framework Client

LocalStack

This is an easy-to-use .NET client for LocalStack. 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.

Continuous integration

Build server Platform Build status
Azure Pipelines Ubuntu Build Status
Azure Pipelines macOs Build Status
Azure Pipelines Windows Build Status

Table of Contents

  1. Supported Platforms
  2. Prerequisites
  3. Installation
  4. Usage
  5. Developing
  6. Changelog
  7. License

Supported Platforms

Prerequisites

To make use of this library, you need to have LocalStack installed on your local machine. In particular, the localstack command needs to be available.

Installation

The easiest way to install LocalStack .NET Client is via nuget:

Install-Package LocalStack.Client

Or use dotnet cli

dotnet add package LocalStack.Client
Package Stable Nightly
LocalStack.Client NuGet MyGet
LocalStack.Client.Extensions NuGet MyGet

Usage

This library provides a thin wrapper around aws-sdk-net. Therefore the usage of this library is same as using AWS SDK for .NET.

See Getting Started with the AWS SDK for .NET

This library can be used with any DI library, AWSSDK.Extensions.NETCore.Setup or it can be used as standalone.

LocalStack.Client.Extensions (Recommended)

LocalStack.Client.Extensions is extensions for the LocalStack.NET Client to integrate with .NET Core configuration and dependency injection frameworks. The extensions also provides wrapper around AWSSDK.Extensions.NETCore.Setup to use both LocalStack and AWS side-by-side.

This approach is recommended since AWSSDK.Extensions.NETCore.Setup is very popular and also it is best practice for using AWSSDK.NET with .NET Core or .NET 5

Installation

The easiest way to install LocalStack .NET Client Extensions is via nuget:

Install-Package LocalStack.Client.Extensions

Or use dotnet cli

dotnet add package LocalStack.Client.Extensions  

Usage

The usage is very similar to AWSSDK.Extensions.NETCore.Setup with some differences.

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

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

The most important difference is that AddAwsService extensions method is used instead of AddAWSService used in AWSSDK.Extensions.NETCore.Setup. The reason for this will be explained later in this section. In addition, the AddLocalStack extension method is also used.

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

You can configure LocalStack.Client by using entries in the appsettings.json files, as shown in the following example.

"LocalStack": {
    "UseLocalStack": true,
    "Session": {
        "AwsAccessKeyId": "my-AwsAccessKeyId",
        "AwsAccessKey": "my-AwsAccessKey",
        "AwsSessionToken": "my-AwsSessionToken",
        "RegionName": "eu-central-1"
    },
    "Config": {
        "LocalStackHost": "localhost",
        "UseSsl": false,
        "UseLegacyPorts": false,
        "EdgePort": 4566
    }
}

All the entries above are has shown with default values (except UseLocalStack, it's false by default). So the above entries do not need to be specified.

What is entered for the aws credential values ​​in the Session section does not matter for LocalStack. RegionName is important since LocalStack creates resources by spesified region.

Config section contains important entries for local development. Starting with LocalStack releases after v0.11.5, all services are now exposed via the edge service (port 4566) only! If you are using a version of LocalStack lower than v0.11.5, you should set UseLegacyPorts to true. Edge port can be set to any available port (see LocalStack configuration section). If you have made such a change in LocalStack's configuration, be sure to set the same port value to EdgePort in the Config section. For LocalStackHost and UseSsl entries, ​​corresponding to the LocalStack configuration should be used.

The following sample setting files can be used to use both LocalStack.Client andAWSSDK.Extensions.NETCore.Setup in different environments.

appsettings.Development.json

"LocalStack": {
    "UseLocalStack": true,
    "Session": {
        ...
    },
    "Config": {
        ...
    }
}

appsettings.Production.json

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

See project LocalStack.Client.Sandbox.WithGenericHost for a use case.

About AddAwsService

AddAwsService is equivalent of AddAWSService used in AWSSDK.Extensions.NETCore.Setup. It decides which factory to use when resolving any AWS Service. To decide this, it checks the UseLocalStack entry. If the UseLocalStack entry is true, it uses the Session class of LocalStack.Client to create AWS Service. If the UseLocalStack entry is false, it uses the ClientFactory class of AWSSDK.Extensions.NETCore.Setup which is also used by original AddAWSService.

It is named as AddAwsService to avoid name conflict with AddAWSService.

Standalone Initialization

If you do not want to use any DI library, you have to instantiate SessionStandalone as follows.

/*
* ==== Default Values ====
* AwsAccessKeyId: accessKey (It doesn't matter to LocalStack)
* AwsAccessKey: secretKey (It doesn't matter to LocalStack)
* AwsSessionToken: token (It doesn't matter to LocalStack)
* RegionName: us-east-1
* ==== Custom Values ====
* var sessionOptions = new SessionOptions("someAwsAccessKeyId", "someAwsAccessKey", "someAwsSessionToken", "eu-central-");
*/
var sessionOptions = new SessionOptions();

/*
* ==== Default Values ====
* LocalStackHost: localhost
* UseSsl: false
* UseLegacyPorts: false (Set true if your LocalStack version is 0.11.5 or above)
* EdgePort: 4566 (It doesn't matter if use legacy ports)
* ==== Custom Values ====
* var configOptions = new ConfigOptions("mylocalhost", false, false, 4566);
*/
var configOptions = new ConfigOptions();

ISession session = SessionStandalone.Init()
                                .WithSessionOptions(sessionOptions)
                                .WithConfigurationOptions(configOptions).Create();

var amazonS3Client = session.CreateClientByImplementation<AmazonS3Client>();

CreateClientByInterface<TSerice> method can also be used to create AWS service, as follows

var amazonS3Client = session.CreateClientByInterface<IAmazonS3>();

Microsoft.Extensions.DependencyInjection Initialization

First, you need to install Microsoft.Extensions.DependencyInjection nuget package as follows

dotnet add package Microsoft.Extensions.DependencyInjection

Register necessary dependencies to ServiceCollection as follows

var collection = new ServiceCollection();

/*
* ==== Default Values ====
* AwsAccessKeyId: accessKey (It doesn't matter to LocalStack)
* AwsAccessKey: secretKey (It doesn't matter to LocalStack)
* AwsSessionToken: token (It doesn't matter to LocalStack)
* RegionName: us-east-1
* ==== Custom Values ====
* var sessionOptions = new SessionOptions("someAwsAccessKeyId", "someAwsAccessKey", "someAwsSessionToken", "eu-central-");
*/
var sessionOptions = new SessionOptions();

/*
* ==== Default Values ====
* LocalStackHost: localhost
* UseSsl: false
* UseLegacyPorts: false (Set true if your LocalStack version is 0.11.4 or below)
* EdgePort: 4566 (It doesn't matter if use legacy ports)
* ==== Custom Values ====
* var configOptions = new ConfigOptions("mylocalhost", false, false, 4566);
*/
var configOptions = new ConfigOptions();

collection
    .AddScoped<ISessionOptions, SessionOptions>(provider => sessionOptions)
    .AddScoped<IConfigOptions, ConfigOptions>(provider => configOptions))
    .AddScoped<IConfig, Config>()
    .AddSingleton<ISessionReflection, SessionReflection>()
    .AddSingleton<ISession, Session>()
    .AddTransient<IAmazonS3>(provider =>
    {
        var session = provider.GetRequiredService<ISession>();

        return (IAmazonS3) session.CreateClientByInterface<IAmazonS3>();
    });

ServiceProvider serviceProvider = collection.BuildServiceProvider();

var amazonS3Client = serviceProvider.GetRequiredService<IAmazonS3>();

If you want to use it with ConfigurationBuilder, you can also choose a usage as below.

var collection = new ServiceCollection();
var builder = new ConfigurationBuilder();

builder.SetBasePath(Directory.GetCurrentDirectory());
builder.AddJsonFile("appsettings.json", true);
builder.AddJsonFile("appsettings.Development.json", true);
builder.AddEnvironmentVariables();
builder.AddCommandLine(args);

IConfiguration configuration = builder.Build();

collection.Configure<LocalStackOptions>(options => configuration.GetSection("LocalStack").Bind(options, c => c.BindNonPublicProperties = true));
/*
* ==== Default Values ====
* AwsAccessKeyId: accessKey (It doesn't matter to LocalStack)
* AwsAccessKey: secretKey (It doesn't matter to LocalStack)
* AwsSessionToken: token (It doesn't matter to LocalStack)
* RegionName: us-east-1
    */
collection.Configure<SessionOptions>(options => configuration.GetSection("LocalStack")
                                                                .GetSection(nameof(LocalStackOptions.Session))
                                                                .Bind(options, c => c.BindNonPublicProperties = true));
/*
    * ==== Default Values ====
    * LocalStackHost: localhost
    * UseSsl: false
    * UseLegacyPorts: false (Set true if your LocalStack version is 0.11.5 or above)
    * EdgePort: 4566 (It doesn't matter if use legacy ports)
    */
collection.Configure<ConfigOptions>(options => configuration.GetSection("LocalStack")
                                                            .GetSection(nameof(LocalStackOptions.Config))
                                                            .Bind(options, c => c.BindNonPublicProperties = true));


collection.AddTransient<IConfig, Config>(provider =>
{
    ConfigOptions options = provider.GetRequiredService<IOptions<ConfigOptions>>().Value;

    return new Config(options);
})
.AddSingleton<ISessionReflection, SessionReflection>()
.AddSingleton<ISession, Session>(provider =>
{
    SessionOptions sessionOptions = provider.GetRequiredService<IOptions<SessionOptions>>().Value;
    var config = provider.GetRequiredService<IConfig>();
    var sessionReflection = provider.GetRequiredService<ISessionReflection>();

    return new Session(sessionOptions, config, sessionReflection);
})
.AddTransient<IAmazonS3>(provider =>
{
    var session = provider.GetRequiredService<ISession>();

    return (IAmazonS3) session.CreateClientByInterface<IAmazonS3>();
});

ServiceProvider serviceProvider = collection.BuildServiceProvider();

var amazonS3Client = serviceProvider.GetRequiredService<IAmazonS3>();

Developing

We welcome feedback, bug reports, and pull requests!

Use commands below to get you started and test your code:

Windows

build.ps1

Linux

./build.sh

About Sandbox Applications

In addition to Unit Tests and Functional Test, LocalStack .Net Repository has various sandbox console applications for both testing and example purposes under tests/sandboxes

Sandbox applications include various examples of initialization methods of LocalStack.Client (see Usage section) and common AWS applications. They provide a convenient and safe environment for those who want to make developments in the library.

To run sandbox applications with LocalStack container, console application called LocalStack.Container has been developed. It uses Dotnet Testcontainer to bootstrap LocalStack. Experiments can be made by running LocalStack.Container application first and then any sandbox application.

Running Tests

Use commands below to run tests

Windows

build.ps1 --target=tests

Linux

./build.sh --target=tests

Changelog

v1.1

  • New endpoints in the official Localstack Python Client v1.10 have been added.
    • Transfer, ACM, CodeCommit, Kinesis Analytics, Amplify, Application Auto Scaling, Kafka, Timestream Query, Timestream Write, Timestream Write, S3 Control, Elastic Load Balancing v2, Redshift Data
  • .NET 5.0 support added.
  • AWSSDK.Core set to 3.5.0 as the minimum version

v1.0

  • New endpoints in the official Localstack Python Client v0.23 have been added.
    • ElastiCache, Kms, Emr, Ecs, Eks, XRay, ElasticBeanstalk, AppSync, CloudFront, Athena, Glue, Api Gateway V2, RdsData, SageMaker, SageMakerRuntime, Ecr, Qldb
  • .netcore2.2 support removed since Microsoft depracated it. .netcore3.1 support added.
  • AWSSDK.Core set to 3.3.106.5 as the minimum version

v0.8.0.163

  • First release

License

Licensed under MIT, see LICENSE for the full text.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].