Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use DefaultRegionChain if AWS_REGION is not specified #8

Merged
merged 1 commit into from
Nov 16, 2023
Merged
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
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