Override AWS ruby SDK global config

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?

pat
gefragt vor 2 Jahren213 Aufrufe
1 Antwort
0

Aws.config is a vanilla Ruby hash. To clear the Aws.config created in the preceding steps within your code, you can use the following method:

  • Aws.config.clear

This will clear out all the global configuration. In the SQS client that follows you can directly configure the credentials and the region.

Reference sample:

require "aws-sdk"

# S3 specific credentials and parameter configuration
Aws.config.update(
  access_key_id: '**************',
  secret_access_key: '**************',,
  region: '******',
  force_path_style: ****
)

s3 = Aws::S3::Client.new()
# S3 specific operations
...
...

# Clear the Aws.config hash
Aws.config.clear

# new SQS client
client = Aws::SQS::Client.new(
  credentials: Aws::Credentials.new(
    '**************',
    '**************',
  ),
  region: '****'
)
AWS
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen