.netamazon-web-servicesamazon-sqslocalstackaws-sdk-net

AWS .NET SDK How to specify region when using Localstack


How do I instantiate a .NET AWSSDK SQS client that has both a custom Region and ServiceURL?


More information:

I have a queue set up in localstack that I can verify is there through an sqs list-queues query using the CLI:

> aws --endpoint-url=http://localhost:4566 --region=ap-southeast-2 sqs list-queues

{
    "QueueUrls": [
        "http://localhost:4566/000000000000/question-renderer-requests-errors",
        "http://localhost:4566/000000000000/question-renderer-requests"
    ]
}

The queues are in region ap-southeast-2, however when I try to access the queues through the SDK, it can't find anything:

var cred = new BasicAWSCredentials("test", "test");

var sqsClientConfig = new AmazonSQSConfig()
{
    RegionEndpoint = RegionEndpoint.APSoutheast2,
    ServiceURL = "http://localhost:4566"
};

var sqsClient = new AmazonSQSClient(cred, sqsClientConfig);

var queues = await sqsClient.ListQueuesAsync(new ListQueuesRequest());

I discovered that RegionEndpoint and ServiceURL are mutually exclusive:

RegionEndpoint and ServiceURL are mutually exclusive properties. Whichever property is set last will cause the other to automatically be reset to null.

I need the service endpoint set to http://localhost:4566 to point to localstack, how do I also set the region endpoint? Am I going the right way about this?

Update: I googled for the default region which is us-east-1, and when I put the queue in there the SDK managed to find it - so it must be a region configuring issue.


Solution

  • Use AuthenticationRegion to specify region (part of IClientConfig)


    var sqsClientConfig = new AmazonSQSConfig()
    {
        RegionEndpoint = RegionEndpoint.APSoutheast2,
        ServiceURL = "http://localhost:4566"
    };
    

    Becomes:

    var sqsClientConfig = new AmazonSQSConfig()
    {
        AuthenticationRegion = "ap-southeast-2",
        ServiceURL = "http://localhost:4566"
    };