2

My mule application writes json record to a kinesis stream. I use KPL producer library. When run locally, it picks AWS credentials from .aws/credentials and writes record to kinesis successfully.

However, when I deploy my application to Cloudhub, it throws AmazonClientException, obviously due to not having access to any of directories that DefaultAWSCredentialsProviderChain class supports. (http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html)

This is how I attach credentials and it looks locally in .aws/credentials:

config.setCredentialsProvider( new 
DefaultAWSCredentialsProviderChain());

I couldn't figure out a way to provide credentials explicitly using my-app.properies file.

Then I tried to create a separate configuration file with getters/setters. set access key and private key as private and then impement a getter:

public AWSCredentialsProvider getCredentials() { 
    if(accessKey == null || secretKey == null) { 
        return new DefaultAWSCredentialsProviderChain(); 
    } 

    return new StaticCredentialsProvider(new BasicAWSCredentials(getAccessKey(), getSecretKey())); 
} 

}

This was intended to be used instead of DefaultAWSCredentialsProviderChain class this way---

config.setCredentialsProvider(new AWSConfig().getCredentials());

Still throws the same error when deployed. The following repo states that it is possible to provide explicit credentials. I need help to figure out how because I can't find a proper documentation / example. https://github.com/awslabs/amazon-kinesis-producer/blob/master/java/amazon-kinesis-producer-sample/src/com/amazonaws/services/kinesis/producer/sample/SampleProducer.java

  • did you look into `PropertiesFileCredentialsProvider` yet? – Jon Oct 27 '17 at 19:07
  • I have not. Trying now. Here is how I am trying to do this, please correct me if I am going in the wrong direction. PropertiesFileCredentialsProvider localProperties = new PropertiesFileCredentialsProvider(credPath); localProperties.getCredentials(); config.setCredentialsProvider(localProperties); – Maga Karaev Oct 27 '17 at 19:33

1 Answers1

0

I have Faced the same issue so, I got this solution I hope this will work for you also.

@Value("${s3_accessKey}")
private String s3_accessKey;

@Value("${s3_secretKey}")
private String s3_secretKey;

//this above  value I am taking from Application.properties file

BasicAWSCredentials creds = new BasicAWSCredentials(s3_accessKey, 
s3_secretKey); 

AmazonS3 s3Client = AmazonS3ClientBuilder.standard().
withCredentials(new AWSStaticCredentialsProvider(creds))
    .withRegion(Regions.US_EAST_2)
    .build();
Rohit Gaidhane
  • 321
  • 2
  • 12