4
votes

Can I get the AWS S3 Website Endpoint URL (like in this table http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteEndpoints.html) through the AWS SDK? I can’t seem to find it.

I need it after programmatically creating a bucket and putting the bucket website settings: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putBucketWebsite-property

1
I’ve currently created a simple map, but I really don’t want to update this whenever Amazon adds/removes regions or modifies the urls: gist.github.com/danielmahal/87522603e1d86fd66948b8c4a25fc010danielmahal
Update your question instead of comment if you want to add more information .zajonc
Thanks @zajonc.The problem was actually that stackoverflow only let me post two linksdanielmahal

1 Answers

4
votes

The pattern of the bucket is ${bucket}.s3-website-<region>.amazonaws.com (This is the more general form and is applicable for all regions, see http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region, while the form ${bucket}.s3-website.<region>.amazonaws.com is not applicable for all regions)

If you want to find out the region name of your bucket you can use the following command

aws s3api get-bucket-location --bucket <your-bucket>

you will get

{
    "LocationConstraint": null
}

This means your bucket has been created in us-east-1 or for any other region you'll get the region name correctly

{
    "LocationConstraint": "eu-central-1"
}

To complement if you really want to build a list of available endpoints, the AWS SDSK (s3 or s3api) does not provide this list (as of today)

The closest you could get using the CLI is to get the list from the ec2 regions. It will assume that when there is a new region where ec2 is deployed, s3 is deployed as well (I cannot guarantee it will not be the case one day but for now its a faire assumption to say if there's a new region ec2 and s3 are at least the services aws will deploy)

so you can run

$ aws ec2 describe-regions
{
    "Regions": [
        {
            "Endpoint": "ec2.ap-south-1.amazonaws.com",
            "RegionName": "ap-south-1"
        },
        {
            "Endpoint": "ec2.eu-west-1.amazonaws.com",
            "RegionName": "eu-west-1"
        },
        {
            "Endpoint": "ec2.ap-southeast-1.amazonaws.com",
            "RegionName": "ap-southeast-1"
        },
        {
            "Endpoint": "ec2.ap-southeast-2.amazonaws.com",
            "RegionName": "ap-southeast-2"
        },
        {
            "Endpoint": "ec2.eu-central-1.amazonaws.com",
            "RegionName": "eu-central-1"
        },
        {
            "Endpoint": "ec2.ap-northeast-2.amazonaws.com",
            "RegionName": "ap-northeast-2"
        },
        {
            "Endpoint": "ec2.ap-northeast-1.amazonaws.com",
            "RegionName": "ap-northeast-1"
        },
        {
            "Endpoint": "ec2.us-east-1.amazonaws.com",
            "RegionName": "us-east-1"
        },
        {
            "Endpoint": "ec2.sa-east-1.amazonaws.com",
            "RegionName": "sa-east-1"
        },
        {
            "Endpoint": "ec2.us-west-1.amazonaws.com",
            "RegionName": "us-west-1"
        },
        {
            "Endpoint": "ec2.us-west-2.amazonaws.com",
            "RegionName": "us-west-2"
        }
    ]
}

you can then apply the pattern ${bucket}.s3-website-<RegionName>.amazonaws.com