.NET
How to use the .NET AWS SDK with LocalStack.
2 minute read
Overview
The AWS SDK for .NET, like other AWS SDKs, lets you set the endpoint when creating resource clients, which is the preferred way of integrating the .NET SDK with LocalStack.
Example
Here is an example of how to create an LambdaClient
with the endpoint set to LocalStack.
var lambdaClient = new AmazonLambdaClient(new AmazonLambdaConfig(
{
ServiceURL = "http://localhost:4566"
}
);
If you want to specify a region and credentials when creating the client, please set them as AuthenticationRegion
and BasicAWSCredentials
, like in this example:
var lambdaClient = new AmazonLambdaClient(new BasicAWSCredentials("test", "test"), new AmazonLambdaConfig(
{
ServiceURL = "http://localhost:4566",
AuthenticationRegion = "eu-west-1"
}
);
Note
Make sure you are setting theAuthenticationRegion
and not the RegionEndpoint
.
Setting the RegionEndpoint
to a constant like RegionEndpoint.EUWest1
will override the ServiceURL, and your request will end up against AWS.S3 specific endpoint
Here is another example, this time with an S3Client
and its specific endpoint.
var config = new AmazonS3Config({ ServiceURL = "http://s3.localhost.localstack.cloud:4566" });
var s3client = new AmazonS3Client(config);
Note
In case of issues resolving this DNS record, we can fallback to http://localhost:4566 in combination with the provider settingForcePathStyle = true
. The S3 service endpoint is slightly different from the other service endpoints, because AWS is deprecating path-style based access for hosting buckets.var config = new AmazonS3Config(
{
ServiceURL = "http://localhost:4566",
ForcePathStyle = true
}
);
var s3client = new AmazonS3Client(config);
Resources
Last modified March 17, 2023: add S3 note for .NET SDK (#521) (c4cce19c7)