user3473445
user3473445

Reputation: 194

How to load AWS credentials from file?

I'm using IVONA SpeachCloud SDK (Create speech sample): https://github.com/IvonaSoftware/ivona-speechcloud-sdk-java/blob/master/src/samples/IvonaSpeechCloudCreateSpeech/SampleIvonaSpeechCloudCreateSpeech.java

Using this code for setting the class path

private static IvonaSpeechCloudClient speechCloud;

private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}

Below is the format for ivona.properties file. File is located in resources directory. Required credentials i've got in my SpeechCloud account

accessKey = mykey 
secretKey = mysecretKey

Below is the exception I am getting

Exception in thread "main" com.amazonaws.AmazonClientException: Unable to load AWS credentials from the /resources/ivona.properties file on the classpath
at com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider.getCredentials(ClasspathPropertiesFileCredentialsProvider.java:81)
at com.ivona.services.tts.IvonaSpeechCloudClient.prepareRequest(IvonaSpeechCloudClient.java:279)
at com.ivona.services.tts.IvonaSpeechCloudClient.prepareRequest(IvonaSpeechCloudClient.java:272)
at com.ivona.services.tts.IvonaSpeechCloudClient.invoke(IvonaSpeechCloudClient.java:259)
at com.ivona.services.tts.IvonaSpeechCloudClient.createSpeech(IvonaSpeechCloudClient.java:148)
at SampleIvonaSpeechCloudCreateSpeech.main(SampleIvonaSpeechCloudCreateSpeech.java:45

How can I solve this exception? Thanks.

Upvotes: 2

Views: 2935

Answers (2)

Rudy B
Rudy B

Reputation: 579

Okay I figured this out after a few hours of messing around in the source files. You can make your own Provider Class where you can pass the credentials in as String Parameters.

This is my custom credential Class "IvonaCredentials"

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;

public class IvonaCredentials implements AWSCredentialsProvider{

public IvonaCredentials(String mSecretKey, String mAccessKey) {
    super();
    this.mSecretKey = mSecretKey;
    this.mAccessKey = mAccessKey;
}

private String mSecretKey;
private String mAccessKey;

@Override
public AWSCredentials getCredentials() {
    AWSCredentials awsCredentials = new AWSCredentials() {

        @Override
        public String getAWSSecretKey() {
            // TODO Auto-generated method stub
            return mSecretKey;
        }

        @Override
        public String getAWSAccessKeyId() {
            // TODO Auto-generated method stub
            return mAccessKey;
        };
    };
    return awsCredentials;
}

@Override
public void refresh() {
    // TODO Auto-generated method stub

}



}

This is how I call my class

private static void init() {
    speechCloud = new IvonaSpeechCloudClient(new IvonaCredentials("secretKey", "accessKey"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}

Upvotes: 3

user3473445
user3473445

Reputation: 194

I've resolved my problem!

I made custom implemention of AWSCredentials class with my secretKey and accessKey

Upvotes: 1

Related Questions