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 Respuesta


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 hace 3 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas