2017-01-12 15 views
6

Tôi đang sử dụng SDK JAVA từ AWS để tạo ứng dụng khách Polly. Như thế này:AWS Polly Java Client cung cấp lỗi: Không thể tải thông tin vùng từ bất kỳ nhà cung cấp nào trong chuỗi

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); 

Khi tôi chạy mã này, tôi nhận được thông báo lỗi sau:

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)

Tôi đã kiểm tra các thông tin bằng cách sử dụng chính sách Simulator IAM. Điều này làm việc tốt, cho phép là OK.

Phương pháp đặt Khu vực trong ClientBuilder KHÔNG hiển thị cho AmazonPollyClientBuilder, vì vậy tôi không có (Java SDK) cách nào để chỉ định khu vực.

Cập nhật: Khi tôi chỉ yêu cầu defaultAwsREgionProviderChain, tôi nhận được thông báo lỗi tương tự

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

Updat 2: Khi tôi tạo ra một tập tin cấu hình trong thư mục de .aws với nội dung sau :

[default] region = eu-west-1

Nó hoạt động, nhưng tôi cần một cách để thiết lập điều này mà không cần dựa vào hệ thống tệp.

Trả lời

5

Cung cấp biến môi trường hệ thống có tên "AWS_REGION" đã thực hiện thủ thuật. Xem ảnh chụp màn hình cho cấu hình trong IBM Bluemix

enter image description here

3

Tôi nghĩ rằng bạn có thể thiết lập khu vực như thế này

AmazonPollyClient apClient = (AmazonPollyClient) AmazonPollyClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(awsCreds)).withRegion("<aws-region>").build(); 
Các vấn đề liên quan