Mat
Mat

Reputation: 2072

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

TL;DR why does AmazonApiGatewayManagementApiClient throwing an AggregateException when trying to use a cloudfront url as ServiceUrl? System.AggregateException: One or more errors occurred. (Credential should be scoped to a valid region, not 'us-east-1'. )

Details

We have a running system were devices connect via websocket to AWS API Gateway.

Device (web socket client) <-> AWS_API_Gateway <-> .net service

this worked good until today. We used the urls provided in the AWS console

aws console urls

We thought it might be a good idea to use cloudfront in order to provide a "real" url (something like https://urlviaCloudfront.mydomain.com/DeviceCenterApi). The device can connect to the url from outside. The connect route is called. The communication from the device to the service does work.

BUT when we try to send data to the connection with the AmazonApiGatewayManagementApiClient we get a exception:

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

This does not happen if we use the "direct" link instead of the custom domain name.

I tried to simplify the code to provide a [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);

Any idea how we can avoid this exception?

Upvotes: 1

Views: 717

Answers (1)

Mat
Mat

Reputation: 2072

I found the reason why this is failing... https://github.com/aws/aws-lambda-dotnet/issues/605

Basically AuthenticationRegion needs to be added to the config.

 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",
};

Upvotes: 2

Related Questions