Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am using the JAVA SDK from AWS to create a 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, I get the following error message:

Exception in thread "main" com.amazonaws.SdkClientException: Unable to load region information from any provider in the chain at com.amazonaws.regions.AwsRegionProviderChain.getRegion(AwsRegionProviderChain.java:56) at com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:319) at com.amazonaws.client.builder.AwsClientBuilder.configureMutableProperties(AwsClientBuilder.java:295) at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:38) at com.eoffice.aws.speech.Polly.main(Polly.java:42)

I checked the credentials using the IAM Policy Simulator. This works fine, permissions are OK.

The method to set the Region in the ClientBuilder is NOT visible for the AmazonPollyClientBuilder, so I have no (Java SDK) way to specify the region.

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

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

Updat 2: When I create a config file in de .aws folder with the following content:

[default] region = eu-west-1

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

like image 584
mpjjonker Avatar asked Jan 12 '17 12:01

mpjjonker


2 Answers

Providing a System Environment variable with name "AWS_REGION" did the trick. See screenshot for configuration in IBM Bluemix

enter image description here

like image 109
mpjjonker Avatar answered Nov 11 '22 15:11

mpjjonker


I think you can set Region like this

AmazonPollyClient apClient = (AmazonPollyClient) AmazonPollyClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(awsCreds)).withRegion("<aws-region>").build();
like image 22
Anteneh Negash Avatar answered Nov 11 '22 15:11

Anteneh Negash