AmazonApiGatewayManagementApiClient throws Credential should be scoped to a valid region, not 'us-east-1'

AmazonApiGatewayManagementApiClient throws Credential should be scoped to a valid region, not 'us-east-1'

TL;DR 为什么 AmazonApiGatewayManagementApiClient 在尝试将云端 url 用作 ServiceUrl 时抛出 AggregateException? System.AggregateException: 发生一个或多个错误。 (凭据应限定在有效区域,而不是 'us-east-1'。)

详情

我们有一个 运行 系统,设备通过 websocket 连接到 AWS API 网关。

设备(网络套接字客户端)<-> AWS_API_Gateway <-> .net 服务

这在今天之前一直有效。我们使用了 AWS 控制台中提供的 urls

我们认为使用云端以提供“真实的”url(类似于 https://urlviaCloudfront.mydomain.com/DeviceCenterApi)可能是个好主意。该设备可以从外部连接到 url。调用连接路由。从设备到服务的通信确实有效。

但是当我们尝试将数据发送到与 AmazonApiGatewayManagementApiClient 的连接时,我们得到一个异常:

System.AggregateException: One or more errors occurred. (Credential should be scoped to a valid region, not 'us-east-1'. )

如果我们使用“直接”link 而不是自定义域名,则不会发生这种情况。

我试图简化代码以提供一个[mcve]:

    AmazonApiGatewayManagementApiConfig configuration = new AmazonApiGatewayManagementApiConfig()
    {
        RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName("eu-west-1"),
        ServiceURL = "https://GENERATEDID.execute-api.eu-west-1.amazonaws.com/DeviceCenterApi",
    };

    //configuration with cloud front url
    AmazonApiGatewayManagementApiConfig notWorkingConfiguration = new AmazonApiGatewayManagementApiConfig()
    {
        RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName("eu-west-1"), // also tried "us-east-1" -> same exception
        ServiceURL = "https://urlviaCloudfront.mydomain.com/DeviceCenterApi",
    };

    AmazonApiGatewayManagementApiClient client = new AmazonApiGatewayManagementApiClient(configuration);

    string connectionId = "M23IVdFmxxxxxxxx=";
    PostToConnectionRequest awsRequest = new PostToConnectionRequest
    {
        ConnectionId = connectionId,
        Data = "Hello world",
    };

    PostToConnectionResponse response = await client.PostToConnectionAsync(awsRequest);

知道如何避免这种异常吗?

我找到了失败的原因... https://github.com/aws/aws-lambda-dotnet/issues/605

基本上AuthenticationRegion需要添加到配置中。

 AmazonApiGatewayManagementApiConfig configuration = new AmazonApiGatewayManagementApiConfig()
{
    AuthenticationRegion = "eu-west-1",
    RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName("eu-west-1"),
    ServiceURL = "https://GENERATEDID.execute-api.eu-west-1.amazonaws.com/DeviceCenterApi",
};