gpt4 book ai didi

.net - AWS .NET SDK 使用 Localstack 时如何指定区域

转载 作者:行者123 更新时间:2023-12-02 01:42:35 25 4
gpt4 key购买 nike

如何实例化同时具有自定义区域和 ServiceURL 的 .NET AWSSDK SQS 客户端?


更多信息:

我在 localstack 中设置了一个队列,我可以使用 CLI 通过 sqs list-queues 查询来验证它是否存在:

> 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"
]
}

队列位于 ap-southeast-2 区域,但是当我尝试通过 SDK 访问队列时,它找不到任何东西:

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());

我发现 RegionEndpointServiceURL 是互斥的:

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

我需要将服务端点设置为 http://localhost:4566 以指向 localstack,如何同时设置区域端点?我的做法是否正确?

更新:我在 google 上搜索了默认区域 us-east-1,当我将队列放在那里时,SDK 设法找到它 - 所以这一定是区域配置问题。

最佳答案

使用 AuthenticationRegion 指定区域(IClientConfig 的一部分)


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

变成:

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

关于.net - AWS .NET SDK 使用 Localstack 时如何指定区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71403539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com