【问题标题】:S3Exception: The bucket you are attempting to access must be addressed using the specified endpointS3Exception:您尝试访问的存储桶必须使用指定的端点进行寻址
【发布时间】:2022-12-01 00:00:13
【问题描述】:

我知道还有很多类似的问题,this one也不例外

但不幸的是,我无法为我的案例决定区域,我该如何决定正确的区域?

比如我在向Postman发起请求的时候,遇到了类似的错误:

在我的控制台中,我使用的是EU (Frankfurt) eu-central-1,也在终端中这样写:

heroku config:set region="eu-central-1"

据我了解,我的不适合。

这也是我的 AWS 课程:

class AmazonFileStorage : FileStorage {

    private val client: S3Client

    private val bucketName: String = System.getenv("bucketName")

    init {
        val region = System.getenv("region")
        val accessKey = System.getenv("accessKey")
        val secretKey = System.getenv("secretKey")

        val credentials = AwsBasicCredentials.create(accessKey, secretKey)
        val awsRegion = Region.of(region)
        client = S3Client.builder()
            .credentialsProvider(StaticCredentialsProvider.create(credentials))
            .region(awsRegion)
            .build() as S3Client
    }

    override suspend fun save(file: File): String =
        withContext(Dispatchers.IO) {
            client.putObject(
                PutObjectRequest.builder().bucket(bucketName).key(file.name).acl(ObjectCannedACL.PUBLIC_READ).build(),
                RequestBody.fromFile(file)
            )
            val request = GetUrlRequest.builder().bucket(bucketName).key(file.name).build()
            client.utilities().getUrl(request).toExternalForm()
        }
}

【问题讨论】:

    标签: amazon-web-services kotlin amazon-s3 heroku


    【解决方案1】:

    我想你可能输入了错误的区号;您知道 Bucket 只在一个区域可用吗?

    在您的日志记录设置中,将此范围设置为调试:

    logging:
      level:
        org.apache.http.wire: debug
    

    然后你应该看到这样的东西:

    http-outgoing-0 >> "HEAD /somefile HTTP/1.1[
    ][
    ]"
    http-outgoing-0 >> "Host: YOURBUCKETNAME.s3.eu-west-2.amazonaws.com[
    ][
    ]"
    

    该日志来自伦敦地区的一个桶eu-west-2

    【讨论】:

      猜你喜欢
      • 2016-10-12
      • 1970-01-01
      • 2016-05-05
      • 2016-03-13
      • 2021-03-29
      • 2016-06-01
      • 2021-04-09
      • 2018-09-14
      相关资源
      最近更新 更多