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


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 Resposta


Have a look at the Java default credentials chain to see all possible ways to supply credentials to the AWS Java SDK:

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.



profile pictureAWS
respondido há 3 meses

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas