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
질문됨 2년 전213회 조회
1개 답변
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
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠