Aws-sdk-ruby: Overriding Service Endpoints (v1 to v2)

Created on 9 Feb 2016  路  1Comment  路  Source: aws/aws-sdk-ruby

Problem

In v1 you were able to override the global endpoint and port for a service from the default config options. Example:

AWS.config(:s3_endpoint => "my.example.endpoint")
AWS.config(:s3_port => 316)

Is this possible in v2? Or do you have to do override it when you create the client for a particular service?

guidance

Most helpful comment

You can do this, the semantics are slightly different. The concept to keep in mind is that we will resolve configuration in roughly the following order:

  1. Locally supplied configuration at client creation time.
  2. Globally defined configuration, scoped to the service.
  3. Globally defined configuration.
  4. Default values.

Or, for a contrived code example:

client = Aws::S3::Client.new(region: "us-east-1")
client.config.endpoint # => #<URI::HTTPS https://s3.amazonaws.com>

Aws.config[:s3] = { endpoint: "https://bar.foo" }
Aws.config[:endpoint] = "https://foo.bar"

ec2 = Aws::EC2::Client.new(region: "us-east-1")
ec2.config.endpoint # => #<URI::HTTPS https://foo.bar>

s3 = Aws::S3::Client.new(region: "us-east-1")
s3.config.endpoint # => #<URI::HTTPS https://bar.foo>

s3_custom = Aws::S3::Client.new(region: "us-east-1", endpoint: "https://my.example.endpoint")
s3_custom.config.endpoint # => #<URI::HTTPS https://my.example.endpoint>

>All comments

You can do this, the semantics are slightly different. The concept to keep in mind is that we will resolve configuration in roughly the following order:

  1. Locally supplied configuration at client creation time.
  2. Globally defined configuration, scoped to the service.
  3. Globally defined configuration.
  4. Default values.

Or, for a contrived code example:

client = Aws::S3::Client.new(region: "us-east-1")
client.config.endpoint # => #<URI::HTTPS https://s3.amazonaws.com>

Aws.config[:s3] = { endpoint: "https://bar.foo" }
Aws.config[:endpoint] = "https://foo.bar"

ec2 = Aws::EC2::Client.new(region: "us-east-1")
ec2.config.endpoint # => #<URI::HTTPS https://foo.bar>

s3 = Aws::S3::Client.new(region: "us-east-1")
s3.config.endpoint # => #<URI::HTTPS https://bar.foo>

s3_custom = Aws::S3::Client.new(region: "us-east-1", endpoint: "https://my.example.endpoint")
s3_custom.config.endpoint # => #<URI::HTTPS https://my.example.endpoint>
Was this page helpful?
0 / 5 - 0 ratings