By using AWS re:Post, you agree to the Terms of Use

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?

asked 22 days ago33 views
1 Answer
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: '****'
)
answered 17 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions