Skip to content

Commit

Permalink
fix: use DefaultRegionChain if AWS_REGION is not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
etolbakov authored Nov 15, 2023
1 parent 635539a commit 800c811
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
use std::env;
use std::string::String;
use aws_config::default_provider::region::DefaultRegionChain;
use aws_types::region::Region;

pub mod iam;
pub mod sts;

/// Retrieves the AWS region from the "AWS_REGION" environment variable if set,
/// otherwise falls back to the default region determined by the DefaultRegionChain.
async fn get_region() -> Region {
env::var("AWS_REGION")
.map(Region::new)
.unwrap_or({
DefaultRegionChain::builder()
.build()
.region()
.await
.expect("Failed to determine the AWS region.")
})
}

pub async fn load_config() -> aws_types::sdk_config::SdkConfig {
let aws_region = env::var("AWS_REGION").unwrap();
let region = Region::new(aws_region);
let region = get_region().await;
aws_config::from_env().region(region).load().await
}
fn remove_whitespace(s: &mut String) {
Expand Down

0 comments on commit 800c811

Please sign in to comment.