aws / aws-sdk-php

Official repository of the AWS SDK for PHP (@awsforphp)
http://aws.amazon.com/sdkforphp
Apache License 2.0
6.04k stars 1.23k forks source link

Invalid AWS Translate service endpoints #2993

Closed fredericgboutin-yapla closed 2 months ago

fredericgboutin-yapla commented 2 months ago

Describe the bug

This morning our automatic translation logic started reporting errors,

Error executing "TranslateDocument" on "https://translate.ca-central.amazonaws.com/"; AWS HTTP error: cURL error 6: Could not resolve host: translate.ca-central.amazonaws.com (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://translate.ca-central.amazonaws.com/ 

And sure enough

traceroute translate.ca-central.amazonaws.com
traceroute: unknown host translate.ca-central.amazonaws.com

Looking at the doc - https://docs.aws.amazon.com/general/latest/gr/translate-service.html - the url should be translate.ca-central-1.amazonaws.com and not translate.ca-central.amazonaws.com - aka it is missing the -1

traceroute translate.ca-central-1.amazonaws.com
traceroute: Warning: translate.ca-central-1.amazonaws.com has multiple addresses; using 35.182.104.126
traceroute to translate.ca-central-1.amazonaws.com (35.182.104.126), 64 hops max, 40 byte packets

So this issue is quite critical as ALL AWS Translate methods stopped working.

Expected Behavior

The AWS Translate Client should poke the proper url so it actually works

Current Behavior

The AWS Translate Client currently poke an invalid url so it fails

Reproduction Steps

$client = new \Aws\Translate\TranslateClient([
            'version' => 'latest',
            'region' => 'ca-central-1'
        ]);
$client->translateDocument([...]);

Possible Solution

As per the doc - https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.AwsClient.html#method___construct - I tried,

$client = new \Aws\Translate\TranslateClient([
            'version' => 'latest',
            'region' => 'ca-central-1',
            'endpoint' => 'https://translate.ca-central-1.amazonaws.com/',
        ]);

But it does NOT work.

You have to pass a full fledge provider,

$client = new \Aws\Translate\TranslateClient([
            'version' => 'latest',
            'region' => 'ca-central-1',
            'endpoint_provider' => fn() => [
                'partition' => 'aws',
                'service' => 'translate',
                'region' => 'ca-central-1',
                'endpoint' => 'https://translate.ca-central-1.amazonaws.com/'
            ]
        ]);

Additional Information/Context

No response

SDK version used

3.321.0

Environment details (Version of PHP (php -v)? OS name and version, etc.)

8.2

fredericgboutin-yapla commented 2 months ago

ha god.... somehow the AWS_REGION got truncated so this is a problem on our side 😞

So, if anybody else see this issue, double-verify the region's value.

BTW, when debugging the code I saw that the vendor/aws/aws-sdk-php/src/EndpointDiscovery/EndpointDiscoveryMiddleware.php has some logic to emit a nice message and to retry with the default endpoint upon error with a custom endpoint. I suppose it could have been nice to have something similar when an invalid endpoint URL is generated because of an invalid region.

Anyway... sorry for the noise.

Cheers,

github-actions[bot] commented 2 months ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.