Skip to content

Commit 23a1a2d

Browse files
authored
fix(aws_s3 source): Allow region to be optional (vectordotdev#18258)
When constructing the client we detect the region so we can use that for consistency rather than requiring it to be specified (so that, for example, `AWS_REGION` is used if set). Signed-off-by: Jesse Szwedko <[email protected]>
1 parent d155a23 commit 23a1a2d

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

src/aws/mod.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,19 @@ pub async fn create_client<T: ClientBuilder>(
149149
tls_options: &Option<TlsConfig>,
150150
is_sink: bool,
151151
) -> crate::Result<T::Client> {
152+
create_client_and_region::<T>(auth, region, endpoint, proxy, tls_options, is_sink)
153+
.await
154+
.map(|(client, _)| client)
155+
}
156+
157+
pub async fn create_client_and_region<T: ClientBuilder>(
158+
auth: &AwsAuthentication,
159+
region: Option<Region>,
160+
endpoint: Option<String>,
161+
proxy: &ProxyConfig,
162+
tls_options: &Option<TlsConfig>,
163+
is_sink: bool,
164+
) -> crate::Result<(T::Client, Region)> {
152165
let retry_config = RetryConfig::disabled();
153166

154167
// The default credentials chains will look for a region if not given but we'd like to
@@ -169,9 +182,10 @@ pub async fn create_client<T: ClientBuilder>(
169182
let config = config_builder.build();
170183

171184
let client =
172-
create_smithy_client::<T>(region, proxy, tls_options, is_sink, retry_config).await?;
185+
create_smithy_client::<T>(region.clone(), proxy, tls_options, is_sink, retry_config)
186+
.await?;
173187

174-
Ok(T::build(client, &config))
188+
Ok((T::build(client, &config), region))
175189
}
176190

177191
pub async fn sign_request(

src/sources/aws_s3/mod.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use super::util::MultilineConfig;
1616
use crate::codecs::DecodingConfig;
1717
use crate::config::DataType;
1818
use crate::{
19-
aws::{auth::AwsAuthentication, create_client, RegionOrEndpoint},
19+
aws::{auth::AwsAuthentication, create_client, create_client_and_region, RegionOrEndpoint},
2020
common::{s3::S3ClientBuilder, sqs::SqsClientBuilder},
2121
config::{
2222
ProxyConfig, SourceAcknowledgementsConfig, SourceConfig, SourceContext, SourceOutput,
@@ -223,16 +223,12 @@ impl AwsS3Config {
223223
proxy: &ProxyConfig,
224224
log_namespace: LogNamespace,
225225
) -> crate::Result<sqs::Ingestor> {
226-
let region = self
227-
.region
228-
.region()
229-
.ok_or(CreateSqsIngestorError::RegionMissing)?;
230-
226+
let region = self.region.region();
231227
let endpoint = self.region.endpoint();
232228

233229
let s3_client = create_client::<S3ClientBuilder>(
234230
&self.auth,
235-
Some(region.clone()),
231+
region.clone(),
236232
endpoint.clone(),
237233
proxy,
238234
&self.tls_options,
@@ -246,9 +242,9 @@ impl AwsS3Config {
246242

247243
match self.sqs {
248244
Some(ref sqs) => {
249-
let sqs_client = create_client::<SqsClientBuilder>(
245+
let (sqs_client, region) = create_client_and_region::<SqsClientBuilder>(
250246
&self.auth,
251-
Some(region.clone()),
247+
region.clone(),
252248
endpoint,
253249
proxy,
254250
&sqs.tls_options,
@@ -284,8 +280,6 @@ enum CreateSqsIngestorError {
284280
Credentials { source: crate::Error },
285281
#[snafu(display("Configuration for `sqs` required when strategy=sqs"))]
286282
ConfigMissing,
287-
#[snafu(display("Region is required"))]
288-
RegionMissing,
289283
#[snafu(display("Endpoint is invalid"))]
290284
InvalidEndpoint,
291285
}

0 commit comments

Comments
 (0)