Skip to content

Commit d0967a6

Browse files
Add config option for disabling region detection (#3349)
1 parent 93985e9 commit d0967a6

6 files changed

Lines changed: 48 additions & 0 deletions

File tree

gems/aws-sdk-sqs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Unreleased Changes
22
------------------
33

4+
* Feature - Support disabling queue url region detection through `disable_queue_url_region_detection`.
5+
46
1.110.0 (2026-01-16)
57
------------------
68

gems/aws-sdk-sqs/lib/aws-sdk-sqs/client.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ class Client < Seahorse::Client::Base
213213
# @option options [Boolean] :disable_host_prefix_injection (false)
214214
# When `true`, the SDK will not prepend the modeled host prefix to the endpoint.
215215
#
216+
# @option options [Boolean] :disable_queue_url_region_detection (false)
217+
# When set to `true`, the region will not be extracted from a provided queue url. Defaults to `false`.
218+
#
216219
# @option options [Boolean] :disable_request_compression (false)
217220
# When set to 'true' the request body will not be compressed
218221
# for supported operations.

gems/aws-sdk-sqs/lib/aws-sdk-sqs/plugins/queue_urls.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ module SQS
55
module Plugins
66
# @api private
77
class QueueUrls < Seahorse::Client::Plugin
8+
# When set to `true`, the signing region will not be modified if the configured
9+
# region does not match the region extracted from a provided queue url.
10+
#
11+
# When set to 'false', the signing region will be modified to use the region
12+
# extracted from a provided queue url if it differs from the configured region.
13+
option(
14+
:disable_queue_url_region_detection,
15+
default: false,
16+
doc_type: 'Boolean',
17+
docstring: <<~DOCS)
18+
When set to `true`, the region will not be extracted from a provided queue url. Defaults to `false`.
19+
DOCS
20+
821
# Extract region from a provided queue_url
922
class Handler < Seahorse::Client::Handler
1023
def call(context)
@@ -22,6 +35,8 @@ def update_endpoint(context, url)
2235
# If the region in the queue url is not the configured
2336
# region, then we will modify signing to use it
2437
def update_region(context, queue_url)
38+
return if context.config.disable_queue_url_region_detection
39+
2540
if (queue_region = parse_region(queue_url)) &&
2641
queue_region != context.config.region
2742
context[:auth_scheme]['signingRegion'] = queue_region

gems/aws-sdk-sqs/sig/client.rbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module Aws
2828
?correct_clock_skew: bool,
2929
?defaults_mode: String,
3030
?disable_host_prefix_injection: bool,
31+
?disable_queue_url_region_detection: bool,
3132
?disable_request_compression: bool,
3233
?endpoint: String,
3334
?endpoint_cache_max_entries: Integer,

gems/aws-sdk-sqs/sig/resource.rbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module Aws
2828
?correct_clock_skew: bool,
2929
?defaults_mode: String,
3030
?disable_host_prefix_injection: bool,
31+
?disable_queue_url_region_detection: bool,
3132
?disable_request_compression: bool,
3233
?endpoint: String,
3334
?endpoint_cache_max_entries: Integer,

gems/aws-sdk-sqs/spec/client/queue_urls_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,32 @@ module SQS
8181
expect(resp.context.http_request.headers['authorization'])
8282
.to include('us-west-2')
8383
end
84+
85+
it 'disables region detection when disable_queue_url_region_detection is true' do
86+
url = 'https://sqs.us-west-2.amazonaws.com/1234567890/demo'
87+
client = Client.new(
88+
stub_responses: true,
89+
region: 'us-east-1',
90+
disable_queue_url_region_detection: true
91+
)
92+
resp = client.send(method, params.merge(queue_url: url))
93+
expect(resp.context.http_request.headers['authorization'])
94+
.to include('us-east-1')
95+
expect(resp.context.http_request.headers['authorization'])
96+
.not_to include('us-west-2')
97+
end
98+
99+
it 'uses configured region for custom endpoints when detection disabled' do
100+
url = 'https://sqs.elb-proxy.elb-gamma.us-east-1.amazonaws.com/1234567890/demo'
101+
client = Client.new(
102+
stub_responses: true,
103+
region: 'us-east-1',
104+
disable_queue_url_region_detection: true
105+
)
106+
resp = client.send(method, params.merge(queue_url: url))
107+
expect(resp.context.http_request.headers['authorization'])
108+
.to include('us-east-1')
109+
end
84110
end
85111
end
86112
end

0 commit comments

Comments
 (0)