我正在使用AWS的JAVA SDK来创建Polly客户端.像这样:
BasicAWSCredentials awsCreds = new BasicAWSCredentials("", "IAM secret key>"); AmazonPollyClient apClient = (AmazonPollyClient) AmazonPollyClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(awsCreds)) .build(); SynthesizeSpeechRequest tssRequest = new SynthesizeSpeechRequest(); tssRequest.setText( ); tssRequest.setVoiceId( ); tssRequest.setOutputFormat(OutputFormat.Mp3); SynthesizeSpeechResult tssResult = apClient.synthesizeSpeech(tssRequest);
当我运行此代码时,我收到以下错误消息:
线程"main"中的异常com.amazonaws.SdkClientException:无法从com.amazonaws.regions.AwsRegionProviderChain.getRegion(AwsRegionProviderChain.java:56)链中的任何提供者加载com.amazonaws.client.builder.AwsClientBuilder的区域信息.setRegion(AwsClientBuilder.java:319)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)
我使用IAM策略模拟器检查了凭据.这工作正常,权限还可以.
在ClientBuilder中设置Region的方法对于AmazonPollyClientBuilder是不可见的,因此我没有(Java SDK)方式来指定区域.
更新: 当我问defaultAwsREgionProviderChain时,我收到相同的错误消息
DefaultAwsRegionProviderChain defaultAwsRegionProviderChain = new DefaultAwsRegionProviderChain(); System.out.println(defaultAwsRegionProviderChain.getRegion());
更新2: 当我在de .aws文件夹中创建一个包含以下内容的配置文件时:
[默认] region = eu-west-1
它有效,但我需要一种方法来设置它而不依赖于文件系统.
提供名为"AWS_REGION"的系统环境变量就可以了.请参阅IBM Bluemix中的配置屏幕截图
我想你可以像这样设置Region
AmazonPollyClient apClient = (AmazonPollyClient) AmazonPollyClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(awsCreds)).withRegion("").build();