I am trying to access an Amazon S3 bucket programmatically through Java libraries. (to do basic cloud management from a third-party application). As a first step, I tried to print whether a bucket exists or not(3rd line)
AWSCredentials credentials=new BasicAWSCredentials("my-Access- Key","My- Secret-Key");
AmazonS3 s3client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials)).withRegion(Regions.AP_EAST_1).build();
String bucketExists=String.valueOf(s3client.doesBucketExistV2("newBucketName"));
When I run this line of code, I am getting an exception saying that
com.amazonaws.services.s3.model.AmazonS3Exception: The AWS Access Key Id you provided does not exist in our records. (Service: Amazon S3; Status Code: 403; Error Code: InvalidAccessKeyId; Request ID:RequestId...)
I don't want to maintain a credentials file in the .aws folder for the following reason:
I am trying to variablilize the access credentials based on the logged-in user from a secure LDAP system, so I can confirm the feasibility only when I test it with hard-coded credentials.
I have checked that the issue is not one of the below
- I have created an IAM user with a valid Access ID and Secret Key in the AWS console and have enabled the user for programmatic access.
- I have also given applied the AmazonS3FullAccess policy for IAM user
- The key is in Active state(have checked it through the console)
- I have added the dependency for the AWS SDK to gradle (implementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.12.15')
Please let me know what the issue might be. My apologies if it is an amateur issue.