Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get Virtually Hosted URL for an S3 resource. #1162

Closed
vineelya opened this issue Mar 22, 2019 · 4 comments
Closed

How to get Virtually Hosted URL for an S3 resource. #1162

vineelya opened this issue Mar 22, 2019 · 4 comments
Labels
guidance Question that needs advice or information.

Comments

@vineelya
Copy link

From S3 Client, when we do getURL(bucket, keyName), we get http://aws_host/bucket/key_path, rather, if I wish to get http://bucket.aws_host/key_path, which API should I use ?

@varunnvs92
Copy link
Contributor

By default, SDK returns virtual hosted style urls http://bucket.aws_host/key_path. You will get path style http://aws_host/bucket/key_path only when you explicitly enable path style option using S3Configuration. Disable that option and you should see the url in the virtual style.

References:
https://github.com/aws/aws-sdk-java-v2/blob/master/services/s3/src/test/java/software/amazon/awssdk/services/s3/S3UtilitiesTest.java#L72-L96
https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro

@vineelya
Copy link
Author

I m using an older version +--- com.amazonaws:aws-java-sdk-s3 -> 1.11.313.

See my complete dependency tree here:

testRuntime - Runtime dependencies for source set 'test' (deprecated, use 'testRuntimeOnly' instead).
+--- com.amazonaws:aws-java-sdk-s3 -> 1.11.313
|    +--- com.amazonaws:aws-java-sdk-kms:1.11.313 -> 1.11.314
|    |    +--- com.amazonaws:aws-java-sdk-core:1.11.314
|    |    |    +--- commons-logging:commons-logging:1.1.3 -> 1.2
|    |    |    +--- org.apache.httpcomponents:httpclient:4.5.5
|    |    |    |    +--- org.apache.httpcomponents:httpcore:4.4.9
|    |    |    |    +--- commons-logging:commons-logging:1.2
|    |    |    |    \--- commons-codec:commons-codec:1.10
|    |    |    +--- software.amazon.ion:ion-java:1.0.2
|    |    |    +--- com.fasterxml.jackson.core:jackson-databind:2.6.7.1
|    |    |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.6.0
|    |    |    |    \--- com.fasterxml.jackson.core:jackson-core:2.6.7
|    |    |    +--- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.6.7
|    |    |    |    \--- com.fasterxml.jackson.core:jackson-core:2.6.7
|    |    |    \--- joda-time:joda-time:2.8.1
|    |    \--- com.amazonaws:jmespath-java:1.11.314
|    |         \--- com.fasterxml.jackson.core:jackson-databind:2.6.7.1 (*)
|    +--- com.amazonaws:aws-java-sdk-core:1.11.313 -> 1.11.314 (*)
|    \--- com.amazonaws:jmespath-java:1.11.313 -> 1.11.314 (*)
+--- org.apache.commons:commons-collections4 -> 4.0
+--- org.apache.commons:commons-lang3 -> 3.0
+--- commons-io:commons-io -> 2.4
+--- commons-lang:commons-lang -> 2.6
+--- org.slf4j:slf4j-api -> 1.7.24
+--- org.slf4j:slf4j-simple -> 1.7.24
|    \--- org.slf4j:slf4j-api:1.7.24
+--- junit:junit -> 4.12
|    \--- org.hamcrest:hamcrest-core:1.3
\--- com.github.stefanbirkner:system-rules:1.19.0
     \--- junit:junit-dep:[4.9,) -> 4.11
          \--- junit:junit:4.11 -> 4.12 (*)

See the below Java test code.

@Test
    public void testAWSS3Client(){

        FastS3Client client = new FastS3Client("us-west-2");
        assertEquals(client.getS3Client().getUrl("dcas_bucket","dcas_key").toString(), "https://s3.us-west-2.amazonaws.com/dcas_bucket/dcas_key");
    }
My client instantiation:
   logger.info("Attempting to instantiate the AWS S3 client for the region  {}", region);
            s3client = AmazonS3ClientBuilder.standard().withRegion(region).withPathStyleAccessEnabled(false).build();
            //Just confirming.
            logger.info("AWS Region {}", s3client.getRegionName());

@varunnvs92
Copy link
Contributor

You are using SDK v1 which is maintained in another repo. Please open future v1 related questions in that repo.

  • Virtual style access is only enabled for buckets that follow DNS compliant names. As your bucket name contains underscore, it is a non-dns-compliant name and so SDK defaults to using path style access.

@justnance justnance added guidance Question that needs advice or information. and removed Question labels Apr 19, 2019
aws-sdk-java-automation added a commit that referenced this issue Jan 22, 2021
…8a6b45a93

Pull request: release <- staging/5d8ffdac-178e-4680-b341-d7a8a6b45a93
@samunbest
Copy link

the same problem occurs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

4 participants