1

I am having a similar issue to one mentioned here. I am using spring xml configurations. I have my global AWS context credentials specified. I am using S3 outbound channel adapter to download a file from S3. I have my keys specified in my config.properties file. I still get don't see the credentials used to talk to S3.

s3-read.xml

<int-aws:s3-outbound-channel-adapter  
               transfer-manager="transferManager"
               bucket-expression="'${s3.bucket}'"
               command-expression="'DOWNLOAD'"
               key-expression="headers.S3Key"
               progress-listener="progressListener" /> 

aws-credentials.xml

<aws-context:context-credentials>
<aws-context:simple-credentials access-key="${aws.accesskey}"
                                secret-key="${aws.secretkey}"/>
</aws-context:context-credentials> 

<!-- Define global region -->
<aws-context:context-region region="${aws.region}"/> 

config.properties

aws.accesskey=accesskey
aws.secretkey=secretkey
aws.region=us-west-2

Exception is:

com.amazonaws.SdkClientException: Unable to load AWS credentials from any 
provider in the chain

I have spent a lot of time with this. When I tried to debug, it seems to look for default credentials provider chain, which is looking for environment variables or ~/.aws/credentials files. I dont have anything specified.

How do I link S3 to use these credentials? Thanks for help.

Preethi
  • 123
  • 8

1 Answers1

0

In my project I used "BasicAWSCredentials" like this

public S3StorageService(AmazonS3Config s3Configs) {
    ClientConfiguration opts = new ClientConfiguration();
    opts.setSignerOverride("S3SignerType");
    BasicAWSCredentials credentials = new BasicAWSCredentials(s3Configs.getAccessKey(), s3Configs.getSecretKey());
    AmazonS3 amazonS3 = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials))
            .withEndpointConfiguration(new EndpointConfiguration(s3Configs.getServiceEndpoint(), ""))
            .withClientConfiguration(opts).build();
    String defaultBucket = s3Configs.getDefaultBucket();

}

@ConfigurationProperties(prefix = "ds31s3.amazon")
public class AmazonS3Config {   
    private String  accessKey;
    private String  secretKey;
    private String  serviceEndpoint;    
    private String  defaultBucket;

in application.properties

#Amazon S3 Configs
ds31s3.amazon.accessKey=<KEY>
ds31s3.amazon.secretKey=<SECRETKEY>
ds31s3.amazon.serviceEndpoint=<ENDPOINT>
ds31s3.amazon.defaultBucket=bucket-karthik

and it worked well.

karthi
  • 224
  • 2
  • 7