Setting up AWS S3 API Java Client credentials

You may get this during Amazon s3 java API client first run:
Exception in thread "main" java.lang.IllegalArgumentException: AWS credential profiles file not found in the given path: /root/.aws/credentials
        at com.amazonaws.auth.profile.internal.ProfilesConfigFileLoader.loadProfiles(ProfilesConfigFileLoader.java:45)
        at com.amazonaws.auth.profile.ProfilesConfigFile.loadProfiles(ProfilesConfigFile.java:173)
        at com.amazonaws.auth.profile.ProfilesConfigFile.<init>(ProfilesConfigFile.java:109)
        at com.amazonaws.auth.profile.ProfilesConfigFile.<init>(ProfilesConfigFile.java:89)
        at com.amazonaws.auth.profile.ProfileCredentialsProvider.getCredentials(ProfileCredentialsProvider.java:117)
        at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3691)
        at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3647)
        at com.amazonaws.services.s3.AmazonS3Client.listObjects(AmazonS3Client.java:626)
        at com.vantage.photowall.toolset.s3client.PhotowallAWSS3Client.listKeys(PhotowallAWSS3Client.java:179)
        at com.vantage.photowall.toolset.s3client.AWSS3BucketAPIClientCLI.main(AWSS3BucketAPIClientCLI.java:55)

To solve this, simply :
Download crendentials file from https://github.com/aws/aws-sdk-java/blob/master/src/samples/AmazonS3/credentials

  1. wget --no-check-certificate https://github.com/aws/aws-sdk-java/raw/master/src/samples/AmazonS3/credentials

put it in ~/.aws/ directory:

  1. mkdir ~/.aws/
  2. mv credentials ~/.aws/credentials

open credentials file and fill access key id and secret access key :

like this:

  1. # Move this credentials file to (~/.aws/credentials)
  2. # after you fill in your access and secret keys in the default profile
  3. # WARNING: To avoid accidental leakage of your credentials,
  4. # DO NOT keep this file in your source directory.
  5. [default]
  6. aws_access_key_id=YOUR_ACCESS_KEY_ID
  7. aws_secret_access_key=YOUR_SECRET_ACCESS_KEY

Save and close the file.
Run API client program again :)

No comments:

Post a Comment