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.