How do I include an S3 bucket name and region/endpoint in a single URL?

后端 未结 3 928
醉梦人生
醉梦人生 2021-02-08 06:54

If I have a bucket named mybucket in region=us-east-1, then I can access it using

aws s3 ls s3://mybucket --region=us-east-1

相关标签:
3条回答
  • 2021-02-08 07:32

    As @michael-sqlbot commented, URL and URI are not the same thing.

    The S3 URL you referenced is actually an S3Uri as mentioned here.

    AWS CLI - S3 Documentation

    S3Uri: represents the location of a S3 object, prefix, or bucket. This must be written in the form s3://mybucket/mykey where mybucket is the specified S3 bucket, mykey is the specified S3 key.

    Uniform Resource Identifier (URI)

    In information technology, a Uniform Resource Identifier (URI) is a string of characters used to identify a resource. Such identification enables interaction with representations of the resource over a network, typically the World Wide Web, using specific protocols. Schemes specifying a concrete syntax and associated protocols define each URI.

    Uniform Resource Locator (URL)

    A Uniform Resource Locator (URL), commonly informally termed a web address (a term which is not defined identically) is a reference to a web resource that specifies its location on a computer network and a mechanism for retrieving it. A URL is a specific type of Uniform Resource Identifier (URI), although many people use the two terms interchangeably.

    So what does this all mean? URL!=URI?

    According to the the definition of what a URI is, it is defined by the scheme designed for it. And, the scheme defined for it in this case, does not include a reference for region.

    So the format for the URI would be correct, even if viewed by others as incomplete.

    A URL is intended to help you locate an object somewhere, where as a URI is intended to reference an object and not necessarily locate it.

    0 讨论(0)
  • 2021-02-08 07:53

    The proper way to include the S3 region for a bucket is to include it in the URL properly.

    Note: "s3.amazonaws.com" is often mis-used when referencing buckets in regions outside of us-east-1. It can be, and often is used to do so. But, doing so makes knowing which region you are actually operating in less obvious, and this can be problematic in some scenerios.

    If you wanted to specifically reference a bucket called "mybucket" in us-east-2 then the best way to do this is one of the following:

    Host-Style Naming: http://mybucket.s3-us-west-2.amazonaws.com
    Path-Style Naming: http://s3-us-west-2.amazonaws.com/mybucket
    

    In either one of those examples, you will always connect to us-west-2 when referencing "mybucket".

    0 讨论(0)
  • 2021-02-08 07:54

    There is no provision in the s3:// scheme for encoding the region.

    Note also that the "U" in URL stands for uniform, not universal.

    0 讨论(0)
提交回复
热议问题