java获取s3对象url,如何通过API获取AWS S3网站端点URL?

博客探讨能否通过AWS SDK获取AWS S3网站端点URL,给出了存储桶URL的通用模式,介绍了查询存储桶所在区域的命令,还提到AWS SDSK未提供可用端点列表,可通过CLI从ec2区域获取列表并应用模式得到URL。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

解决方案

The pattern of the bucket is ${bucket}.s3-website-.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..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

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-.amazonaws.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值