1

I'm making a service that will allow clients to do text-to speech in the browser for language-learning purposes.

The the client will submit the text to the backend server, which will send back a pre-signed request url for the AWS Polly service. The client will then request the audio directly from AWS Polly.

Because this is audio, the documentation makes it clear that the AWS region specified is important for minimizing latency. However my clients can be anywhere, and I need to determine the closest AWS region to them.

I have seen only answers that involve extremely complicated solutions to this, but some of them are old.

Is there a simple way to make sure that my AWS request goes to the closest region to the client? I'll have access to their IP I suspect in most cases.

To be clear I need the actual text region (eg 'us-east-2')

const client = new Polly({
    region: "REGION",
    credentials: fromCognitoIdentityPool({
        client: new CognitoIdentityClient({ region: "REGION" }),
        identityPoolId: "IDENTITY_POOL_ID" // IDENTITY_POOL_ID
    }),
});

Update**

It looks like I can probably cobble together ip-range-check and ip-ranges.json to get this done programmatically without DNS lookup.

Anyone want to make an NPM package for me? Maybe this will be my first NPM package, lol.

pixelearth
  • 13,674
  • 10
  • 62
  • 110
  • 1
    maybe route53 geolocation routing? https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html#routing-policy-geo – jordanm Nov 24 '21 at 21:23
  • Route53 latency records are often used for that. – Marcin Nov 24 '21 at 21:45
  • I've updated my question for clarity. I need the actual region in a string (eg 'us-east-2'), to pass to the `Polly` client constructor. I'm not really sure how to get that from route53. Could you clarify the approach you're suggesting. Again, this request is going to AWS Polly service itself, not one of my own servers in a specific location. – pixelearth Nov 24 '21 at 23:03
  • 1
    If you use Route53 geolocation or latency record, your clients go to best region. So if a request reaches your backend in that region, you already know which region it is in. Its the region with the backend handling the request. – Marcin Nov 25 '21 at 00:22
  • My backend is not hosted on a AWS. And even if it were, it is not necessarily going to be in multiple regions. Definitely not all of the regions. I'm just using this one simple service from AWS. – pixelearth Nov 25 '21 at 13:44

0 Answers0