AWS Polly Java Client gives error: Unable to load region information from any provider in the chain

I am using AWS JAVA SDK to create Polly client. Like this:

BasicAWSCredentials awsCreds = new BasicAWSCredentials("<IAM access Key>", "IAM secret key>"); AmazonPollyClient apClient = (AmazonPollyClient) AmazonPollyClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(awsCreds)) .build(); SynthesizeSpeechRequest tssRequest = new SynthesizeSpeechRequest(); tssRequest.setText(<text>); tssRequest.setVoiceId(<voiceid>); tssRequest.setOutputFormat(OutputFormat.Mp3); SynthesizeSpeechResult tssResult = apClient.synthesizeSpeech(tssRequest); 

When I run this code, the following error message appears:

The exception is in the topic "main" com.amazonaws.SdkClientException: information about the download region from any provider in the chain on com.amazonaws.regions.AwsRegionProviderChain.getRegion (AwsRegionProviderChain.java:56) in com.amazonaws.client.builder.AwsClientBuilder is not possible. setRegion (AwsClientBuilder.javahaps19) in com.amazonaws.client.builder.AwsClientBuilder.configureMutableProperties (AwsClientBuilder.java:295) in com.amazonaws.client.builder.AwsSyncClientBuildersbuj.client.uild.ujec.ju com .aws.speech.Polly.main (Polly.java:42)

I checked the credentials using the IAM policy simulator. This works fine, permissions are ok.

The area setting method in ClientBuilder is NOT displayed for AmazonPollyClientBuilder, so I have no (Java SDK) way to specify the area.

Update: When I just ask defaultAwsREgionProviderChain, I get the same error message

 DefaultAwsRegionProviderChain defaultAwsRegionProviderChain = new DefaultAwsRegionProviderChain(); System.out.println(defaultAwsRegionProviderChain.getRegion()); 

Update 2: When I create a configuration file in the de.aws folder with the following contents:

[default] region = eu-west-1

This works, but I need a way to install this without relying on the file system.

+6
source share
2 answers

Providing a System Environment variable named "AWS_REGION" did the trick. See screenshot for configuration on IBM Bluemix

enter image description here

+5
source

I think you can set Region like this

 AmazonPollyClient apClient = (AmazonPollyClient) AmazonPollyClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(awsCreds)).withRegion("<aws-region>").build(); 
+3
source

Source: https://habr.com/ru/post/1014012/


All Articles