Reputation: 21
I am getting below error while trying to access ibm cloud storage
Container storage location with specified provisioning code not available (Service: Amazon > Status Code: 400.
Please see the snippet of code of i am using to create a bucket in ibm cloud storage using aws s3 client sdk.
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");
The above code is working only for us-south end point(s3.us-south.cloud-object-storage.appdomain.cloud)
As per the ibm official docs[0] there are the other endpoints for different regions, but none of them is working using above code.
Upvotes: 0
Views: 850
Reputation: 2865
I am taking an example of how to use Java SDK with region/location specified
String location = "us";
AmazonS3 cosClient = createClient(apiKey, serviceInstanceId, endpointUrl, location);
The createClient
static method looks like this
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();
}
As per the documentation here, AmazonS3ClientBuilder
has an option to pass the region using withRegion
.
Check the complete COS Java SDK documentation here
Updated:
If you see the Java example in the COS documentation, there is something called Storage class.
storageClass is a valid provisioning code that corresponds to the endpoint value. This is then used as the S3 API LocationConstraint variable.
To create a bucket with a different storage class programmatically, it is necessary to specify a LocationConstraint that corresponds with the endpoint used.
You can find the valid provisioning codes for LocationConstraint in the documentation here
Further read - API documentation:
Upvotes: 0