javaspringamazon-web-servicesspring-bootaws-sdk

credentials to the AWS SDK 1.12.780 for Java


I want to set the Environment variables-AWS_ACCESS_KEY_ID, AWS_SECRET_KEY or AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN

BasicSessionCredentials awsCreds = new BasicSessionCredentials("access_key_id", "secret_key_id", "session_token");
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                        .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
                        .build();

but from the console I only have the AWS_ACCESS_KEY_ID, AWS_SECRET_KEY, not the token:

enter image description here


Solution

  • Two things:

    1. Use BasicAWSCredentials to pass just an accessKey and secretKey. The session one isn't needed for simple applications. It's used for short term / temporary credentials and if you're just starting out, keep it simple.
    2. You're using version 1 of the Java SDK if you're using BasicSessionCredentials. While Amazon still supports version 1 of the Java SDK they have already stopped general support and will drop all support at the end of 2025. The AWS Java SDK version 2 has been out for quite some time and is super stable - I'd strongly encourage you to use it instead.