Accessing s3 using credentials stored in laptop in .aws folder through Java

0

I am trying to access to s3 using Java. the credentials are stored in my laptop, but when i specify the credentials in code, its showing that the key doesn't exist.

Error:The AWS Access Key Id you provided does not exist in our records. (Service: S3, Status Code: 403, Request ID: ,,,,,,) Code written: Region region = Region.US_EAST_1;

String bucketname="x"; String keyname="y"; String Accesskey="z"; String Secretkey="t";

AwsBasicCredentials credentials=AwsBasicCredentials.create(Accesskey,Secretkey); AwsCredentialsProvider provider = StaticCredentialsProvider.create(credentials);

S3Client client = S3Client.builder().region(region) .credentialsProvider(provider) .build();

GetObjectRequest objectRequest = GetObjectRequest.builder() .bucket(bucketname) .key(keyname) .build();

1 Antwort
0

Hi,

Have a look at the Java default credentials chain to see all possible ways to supply credentials to the AWS Java SDK: https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/credentials-chain.html

I personally use the env variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to avoid storing my credentials in my source code, which is a bad practice.

Best,

Didier

profile pictureAWS
EXPERTE
beantwortet vor 3 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen