IBM / ibm-cos-sdk-js

ibm-cos-sdk-js
Apache License 2.0
38 stars 20 forks source link

What credentials to use? #91

Closed instakarlo closed 2 years ago

instakarlo commented 2 years ago

Hi,

I am getting this error when I try to list buckets: Error: Access Denied

I get my credentials from IBM Cloud > COS > Svc Credentials: image

Sample credential will look like this:

{
  "apikey": "1234",
  "endpoints": "https://ibm.com/v2/endpoints",
  "iam_apikey_description": "Auto-generated for key crn:v1:bluemix:public:cloud-object-storage:global:a/bf:2b8:resource-key:690",
  "iam_apikey_name": "api-key-name",
  "iam_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Writer",
  "iam_serviceid_crn": "crn:v1:bluemix:public:iam-identity::a/bf::serviceid:ServiceId-abcdef",
  "resource_instance_id": "crn:v1:bluemix:public:cloud-object-storage:global:abf:2b8::"
}

My code looks like this:

const ibm = require('ibm-cos-sdk');
const util = require('util');

const config = {
    endpoint: 'https://s3.us-south.cloud-object-storage.appdomain.cloud',
    apiKeyId: '1234',
    serviceInstanceId: 'ServiceId-abcdef',
};

const cos = new ibm.S3(config);

const getBuckets = () => {
    console.log('Retrieving list of buckets');
    return cos.listBuckets()
    .promise()
    .then((data) => {
        if (data.Buckets != null) {
            for (const i = 0; i < data.Buckets.length; i++) {
                console.log(`Bucket Name: ${data.Buckets[i].Name}`);
            }
        }
    })
    .catch((e) => {
        console.error(`ERROR: ${e.code} - ${e.message}\n`);
    });
}

module.exports = {
    getBuckets
}

But it keeps having the error. Am I doing it correctly? TY!!!

IBMeric commented 2 years ago

Thanks for your question. You want to use resource_instance_id for the service instance ID. The field is unfortunately named and cannot change for legacy reasons.

If your issue is resolved, please close the ticket.

IBMeric commented 2 years ago

Closing as resolved