Home > Software design >  Ignore AWS ruby SDK global config
Ignore AWS ruby SDK global config

Time:09-11

I'm working with the AWS ruby SDK and trying to override the global config for a specific client.

When I load the application I set the global config for S3 use like this

Aws.config.update(
  endpoint: '****',
  access_key_id: '****',
  secret_access_key: '****',
  force_path_style: '*****',
  region: '****'
)

At some point in the application I want to use a different AWS SDK and make those calls using a different set of config options. I create a client like this

client = Aws::SQS::Client.new(
  credentials: Aws::Credentials.new(
    '****',
    '****'
  ),
  region: '****'
)

When I make a call using this new client I get errors because it uses the new config options as well as the ones defined in the global config. For example, I get an error for having force_path_style set because SQS doesn't allow that config option.

Is there a way to override all the global config options for a specific call?

CodePudding user response:

Aws.config supports nested service-specific options, so you can set global options specifically for S3 without affecting other service clients (like SQS).

This means you could change your global config to nest force_path_style under a new s3 hash, like this:

Aws.config.update(
  endpoint: '****',
  access_key_id: '****',
  secret_access_key: '****',
  s3: {force_path_style: '*****'},
  region: '****'
)
  • Related