0

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?

Ted
  • 15
  • 1
  • 4
  • I am not using AWS SDK directly. Yet I would suggest to not use a default config. You can then add `force_path_style` only when required (S3 I guess) – Maxence Sep 09 '22 at 21:51
  • That would work but I'm using an open source project and making that change would require quite a few changes on my end which I want to try to avoid. I was hoping there would be a way that AWS built in to just override the global config options but I haven't found anything yet. – Ted Sep 09 '22 at 22:49

1 Answers1

1

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: '****'
)
Jimmy
  • 81
  • 2
  • Awesome, this works great. It allows me to make minimal changes to the open source project for now. Thanks! – Ted Sep 10 '22 at 21:19