Get URL(link) of a public S3 object programmatically

For Java SDK 2

s3Client.utilities().getUrl(builder -> builder.bucket(AWS_BUCKET).key(s3RelativeFilePath)).toExternalForm();

Reference - https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/S3Utilities.html#getUrl-java.util.function.Consumer-

older versions had:

s3Client.getResourceUrl(bucket, s3RelativeToBucketPath);

For SDK-2 version, Kotlin:

s3.utilities().getUrl { it.bucket("BUCKET").key("FILEPATH") }.toExternalForm()

i am using aws-java-sdk-s3 1.11.58

accepted answer not working on this version.

below line works for this version

s3Client.getUrl(AWS_BUCKET, s3RelativeFilePath).toExternalForm();