Rami Khawaly
Rami Khawaly

Reputation: 115

Getting Unable to load AWS credentials from any provider in the chain error

I'm getting the following exception when trying to upload a file to AWS Glacier Error: Unable to load AWS credentials from any provider in the chain

I created an accessKey and SecretKey. the code I'm running is similar to the one was suggest here it is:

    public static String vaultName = "myName";
    public static String archiveId = "*** provide archive ID ***";
    public static String archiveToUpload  =  "C:\\dev\\file.txt";
    

public final static String AWS_DATACENTER_URL = "eu-central-1.amazonaws.com/";
    public final static String GLACIER_URL = "glacier."+AWS_DATACENTER_URL;
    public final static String SQS_URL = "sqs."+AWS_DATACENTER_URL;
    public final static String SNS_URL = "sns."+AWS_DATACENTER_URL;
    public final static String HTTPS_URL = "https://"+GLACIER_URL;
    public final static AWSCredentialsProvider credentials = new ClasspathPropertiesFileCredentialsProvider();
    public static void main(String[] args) {
        
        System.out.println("credentials AKID:" + credentials.getCredentials().getAWSAccessKeyId() + " SK:" + credentials.getCredentials().getAWSSecretKey());
        
        
        AmazonGlacierClient client = new AmazonGlacierClient();
        client.setEndpoint(HTTPS_URL);
        
        ArchiveTransferManager atm = new ArchiveTransferManager(client, credentials);
        try
        {
            archiveId = atm.upload(vaultName, "Tax 2012 documents", new File(archiveToUpload)).getArchiveId();
            System.out.println("uploaded:" + archiveId);
        }
        catch (AmazonClientException
                | FileNotFoundException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

my credentials file is in the following format (the credentials object is reading it properly):

accessKey=MY_KEY
secretKey=MY_SECRET_KEY

what I'm missing??

Upvotes: 0

Views: 148

Answers (1)

Mark B
Mark B

Reputation: 200562

Since you are using a non-standard method for setting credentials, you need to pass the credentials object to the client, like so:

AmazonGlacierClient client = new AmazonGlacierClient(credentials);

Upvotes: 1

Related Questions