Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/aws/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ pub enum AwsAuthentication {
/// Configuration for authenticating with AWS through IMDS.
#[serde(default)]
imds: ImdsAuthentication,

/// The [AWS region][aws_region] to send STS requests to.
///
/// If not set, this defaults to the configured region
/// for the service itself.
///
/// [aws_region]: https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints
#[configurable(metadata(docs::examples = "us-west-2"))]
region: Option<String>,
},
}

Expand Down Expand Up @@ -213,8 +222,14 @@ impl AwsAuthentication {
AwsAuthentication::Default {
load_timeout_secs,
imds,
region,
} => Ok(SharedCredentialsProvider::new(
default_credentials_provider(service_region, *load_timeout_secs, *imds).await?,
default_credentials_provider(
region.clone().map(Region::new).unwrap_or(service_region),
*load_timeout_secs,
*imds,
)
.await?,
)),
}
}
Expand Down Expand Up @@ -294,10 +309,28 @@ mod tests {
AwsAuthentication::Default {
load_timeout_secs: Some(10),
imds: ImdsAuthentication { .. },
region: None,
}
));
}

#[test]
fn parsing_default_with_region() {
let config = toml::from_str::<ComponentConfig>(
r#"
auth.region = "us-east-2"
"#,
)
.unwrap();

match config.auth {
AwsAuthentication::Default { region, .. } => {
assert_eq!(region.unwrap(), "us-east-2");
}
_ => panic!(),
}
}

#[test]
fn parsing_default_with_imds_client() {
let config = toml::from_str::<ComponentConfig>(
Expand All @@ -313,6 +346,7 @@ mod tests {
config.auth,
AwsAuthentication::Default {
load_timeout_secs: None,
region: None,
imds: ImdsAuthentication {
max_attempts: 5,
connect_timeout: CONNECT_TIMEOUT,
Expand Down
1 change: 1 addition & 0 deletions src/sinks/aws_kinesis/firehose/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ async fn firehose_put_records() {
auth: Some(ElasticsearchAuth::Aws(AwsAuthentication::Default {
load_timeout_secs: Some(5),
imds: ImdsAuthentication::default(),
region: None,
})),
endpoints: vec![elasticsearch_address()],
bulk: BulkConfig {
Expand Down
3 changes: 3 additions & 0 deletions src/sinks/elasticsearch/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ async fn auto_version_aws() {
auth: Some(ElasticsearchAuth::Aws(AwsAuthentication::Default {
load_timeout_secs: Some(5),
imds: ImdsAuthentication::default(),
region: None,
})),
endpoints: vec![aws_server()],
aws: Some(RegionOrEndpoint::with_region(String::from("localstack"))),
Expand Down Expand Up @@ -346,6 +347,7 @@ async fn insert_events_on_aws() {
auth: Some(ElasticsearchAuth::Aws(AwsAuthentication::Default {
load_timeout_secs: Some(5),
imds: ImdsAuthentication::default(),
region: None,
})),
endpoints: vec![aws_server()],
aws: Some(RegionOrEndpoint::with_region(String::from("localstack"))),
Expand All @@ -368,6 +370,7 @@ async fn insert_events_on_aws_with_compression() {
auth: Some(ElasticsearchAuth::Aws(AwsAuthentication::Default {
load_timeout_secs: Some(5),
imds: ImdsAuthentication::default(),
region: None,
})),
endpoints: vec![aws_server()],
aws: Some(RegionOrEndpoint::with_region(String::from("localstack"))),
Expand Down