rubyibm-cloud-infrastructurefogobject-storageibm-cloud-storage

Fog/aws gem for IBM Cloud Object Storage is not working


As Softlayer or IBM Cloud has moved from Swift based Object Storage to S3 based Cloud Object Storage. I am using fog/aws instead of fog/softlayer.

The below is the code:

require 'fog/aws'
fog_properties = {
  provider: 'AWS',
  aws_access_key_id: username,
  aws_secret_access_key: api_key
}
@client = Fog::Storage.new(fog_properties)
@client.directories

But it failed even with valid key and id.


<Error><Code>InvalidAccessKeyId</Code><Message>The AWS Access Key Id you provided does not exist in our records.\</Message><AWSAccessKeyId>####</AWSAccessKeyId><RequestId>####</RequestId><HostId>##</HostId></Error>

End Point IBM COS uses is "https://control.cloud-object-storage.cloud.ibm.com/v2/endpoints"

When I tried to use fog alone(require 'fog'). It throws the below error:

Unable to activate google-api-client-0.23.9, because mime-types-2.99.3 conflicts with mime-types (~> 3.0) (Gem::ConflictError)

Please suggest how to resolve these issues.


Solution

  • The following code worked for IBM Cloud Objects Storage

    properties = {
              region: region,
              endpoint: URI('https://s3.us-south.cloud-object-storage.appdomain.cloud'),
              credentials: Aws::Credentials.new(access_key_id, secret_access_key)
            }
            Aws.config.update(properties)
            @client = Aws::S3::Client.new
    

    Properties for the config can also be set as ENV variables.

    Below are few basic operations performed on COS.

    List all the bucker names

    @client.list_buckets.buckets.map(&:name)

    Create Bucket

    @client.create_bucket(bucket: )

    Upload a file

    @client.put_object(bucket: , key: , body: )

    Download a file

    @client.get_object(bucket: , key: )

    Delete a file

    @client.delete_object(bucket: , key: )

    Delete a Bucket

    @client.delete_bucket(bucket: )