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回答
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
エキスパート
回答済み 3ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ