The https://aws.amazon.com/sdk-for-java/ team is pleased to announce the general availability of https://aws.amazon.com/s3/ URI parsing in the https://github.com/aws/aws-sdk-java-v2. You can now parse path-style and virtual-hosted-style S3 URIs to easily retrieve the bucket, key, region, style, and query parameters.

Users often need to extract important components like bucket and key from stored S3 URIs to use in S3Client operations.

String url = "https://s3.us-west-1.amazonaws.com/myBucket/resources/doc.txt?versionId=abc123&partNumber=77&partNumber=88"; URI uri = URI.create(url); S3Uri s3Uri = s3Utilities.parseUri(uri); With the S3Uri, you can call the appropriate getter methods to retrieve the bucket, key, region, style, and query parameters.

In this post, I discussed parsing S3 URIs in the AWS SDK for Java 2.x and provided code examples for retrieving the bucket, key, region, style, and query parameters.

Related Articles