【问题标题】:IBM cloud storage, getting error while creating bucket with aws sdkIBM 云存储,使用 aws sdk 创建存储桶时出错
【发布时间】:2020-10-14 06:17:04
【问题描述】:

我在尝试访问 ibm 云存储时遇到错误

具有指定配置代码的容器存储位置不可用(服务:亚马逊>状态代码:400。

请查看我使用 aws s3 客户端 sdk 在 ibm 云存储中创建存储桶的代码的 sn-p。

    String accessKey = (ACCESS_KEY);
    String secretKey = (SECRET_KEY);
    AWSCredentials credentials = new BasicAWSCredentials(accessKey,
            secretKey);
    AmazonS3Client s3service = new AmazonS3Client(credentials);
    s3service.setEndpoint(END_POINT);
    s3service.createBucket("samplebucket");

以上代码仅适用于 us-south 端点(s3.us-south.cloud-object-storage.appdomain.cloud)

根据 ibm 官方文档[0],还有针对不同区域的其他端点,但它们都没有使用上述代码。

[0]-https://cloud.ibm.com/docs/cloud-object-storage-infrastructure?topic=cloud-object-storage-infrastructure-select-regions-and-endpoints

【问题讨论】:

  • 官方文档在这里:cloud.ibm.com/docs/…。请添加您尝试过的所有参数,除了您的凭据。
  • 这个sn-p代码对我不起作用:String accessKey = (ACCESS_KEY); String secretKey = (SECRET_KEY); AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AmazonS3Client s3service = new AmazonS3Client(credentials); s3service.setEndpoint("https://s3.us-east.cloud-object-storage.appdomain.cloud"); s3service.createBucket("samplebucket");

标签: websphere ibm-cloud cloud-storage


【解决方案1】:

我举一个例子来说明如何使用指定区域/位置的 Java SDK

String location = "us"; 
AmazonS3 cosClient = createClient(apiKey, serviceInstanceId, endpointUrl, location);

createClient 静态方法如下所示

 public static AmazonS3 createClient(String apiKey, String serviceInstanceId, String endpointUrl, String location)
        {
            AWSCredentials credentials = new BasicIBMOAuthCredentials(apiKey, serviceInstanceId);
            ClientConfiguration clientConfig = new ClientConfiguration()
                    .withRequestTimeout(5000)
                    .withTcpKeepAlive(true);

            return AmazonS3ClientBuilder
                    .standard()
                    .withCredentials(new AWSStaticCredentialsProvider(credentials))
                    .withEndpointConfiguration(new EndpointConfiguration(endpointUrl, location))
                    .withPathStyleAccessEnabled(true)
                    .withClientConfiguration(clientConfig)
                    .build();
        }

根据documentation hereAmazonS3ClientBuilder 可以选择使用withRegion 传递区域。

查看完整的 COS Java SDK documentation here

更新:

如果您在COS documentation 中看到 Java 示例,则有一个名为 存储类的东西。

storageClass 是对应于 端点值。然后将其用作 S3 API LocationConstraint 变量。

要以编程方式创建具有不同存储类的存储桶,需要指定与使用的端点对应的 LocationConstraint。

您可以在 documentation here 中找到 LocationConstraint 的有效配置代码

进一步阅读 - API 文档:

【讨论】:

  • 感谢 Vidyasage,但我的 sn-p 代码适用于一个端点,而不适用于其他端点。我从他们的文档中获取了 ibm 端点
  • 您是否看到任何错误代码以及状态代码?你能提供完整的错误吗?
  • @Neeraj 用 LocationConstraint 信息更新了我的答案
  • @vidyasage 我想在与客户端配置的端点相同的区域中创建存储桶。如果您看到 AmazonS3Client class(https://github.com/IBM/ibm-cos-sdk-java/blob/master/ibm-cos-java-sdk-s3/src/main/java/com/ibm/cloud/objectstorage/services/s3/AmazonS3Client.java) 具有 createBucket 函数并且不需要指定任何存储类。这个特定的类函数不起作用。
  • 只是总结一下我的查询:这个特定的类函数[0]不适用于我的端点(除了我们-南端点)[0] - ibm.github.io/ibm-cos-sdk-java/com/ibm/cloud/objectstorage/…
猜你喜欢
  • 1970-01-01
  • 2015-02-14
  • 2020-07-22
  • 2020-07-16
  • 2016-01-31
  • 2017-09-13
  • 2020-05-04
  • 1970-01-01
  • 2021-08-04
相关资源
最近更新 更多