如何通过API获取AWS S3网站端点URL? [英] How do I get the AWS S3 Website Endpoint URL through the API?
问题描述
我是否可以获取AWS S3网站端点URL(如该表通过AWS开发工具包http://docs.aws.amazon.com/AmazonS3/latest/dev/WebsiteEndpoints.html )?我似乎找不到它.
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.
以编程方式创建存储桶并放置存储桶网站设置后,我需要它: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putBucketWebsite-property
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
推荐答案
存储桶的模式为${bucket}.s3-website-<region>.amazonaws.com
(这是更通用的形式,适用于所有区域,请参见
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>
您将获得
{
"LocationConstraint": null
}
这意味着您的存储桶已在 us-east-1
中创建
或对于其他任何区域,您都会正确获得区域名称
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"
}
作为补充,如果您确实要构建可用端点的列表,则AWS SDSK(s3
或s3api
)不提供此列表(截至今天)
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)
使用CLI可获得的最接近的结果是从ec2区域中获取列表.它将假设在有新区域部署ec2的同时,也部署了s3(我不能保证有一天不会出现这种情况,但现在可以合理地假设是否有新区域ec2和s3是至少aws将部署的服务)
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)
因此您可以运行
$ 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"
}
]
}
然后您可以应用图案${bucket}.s3-website-<RegionName>.amazonaws.com
这篇关于如何通过API获取AWS S3网站端点URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!