Google Cloud Storage Connection with Access-Key and Secret-Key (without client-secret json)

Viewed 167

I am trying to connect to Google Cloud Storage with AccessKey and SecretKey. I found that there is GoogleCloudStorage repository available for connecting. But its require to have a client-secret.json file that should be pointed by ENV Variable.

I am looking for the way that I can connect with Google Cloud Storage with given AccessKey and SecretKey only.

Thanks in Advance for any kind of lead or help

1 Answers
constructor(accessKeyId: string, secretAccessKey: string) {
  let gcsConfig: any = {
    accessKeyId: null,
    secretAccessKey: null,
    endpoint: new AWS.Endpoint('https://storage.googleapis.com'),
  }
    
  if (!_.isEmpty(accessKeyId) && !_.isEmpty(secretAccessKey)) {
    gcsConfig.accessKeyId = accessKeyId;
    gcsConfig.secretAccessKey = secretAccessKey;
    this.gcs = new AWS.S3(gcsConfig);   
  }
}

This work like charm By default, google cloud storage provide a key pair(access_key, secret_key), we can use it with Amazon SDK and add one more param endpoint: new AWS.Endpoint('https://storage.googleapis.com')

Related