|
12 | 12 | use bottlecap::lwa::proxy::start_lwa_proxy; |
13 | 13 | use bottlecap::{ |
14 | 14 | base_url, |
15 | | - config::{self, get_aws_partition_by_region, AwsConfig, Config}, |
| 15 | + config::{ |
| 16 | + self, |
| 17 | + aws::{build_lambda_function_arn, AwsConfig}, |
| 18 | + Config, |
| 19 | + }, |
16 | 20 | event_bus::bus::EventBus, |
17 | 21 | events::Event, |
18 | 22 | lifecycle::{ |
@@ -179,11 +183,6 @@ async fn register(client: &Client) -> Result<RegisterResponse> { |
179 | 183 | Ok(register_response) |
180 | 184 | } |
181 | 185 |
|
182 | | -fn build_function_arn(account_id: &str, region: &str, function_name: &str) -> String { |
183 | | - let aws_partition = get_aws_partition_by_region(region); |
184 | | - format!("arn:{aws_partition}:lambda:{region}:{account_id}:function:{function_name}") |
185 | | -} |
186 | | - |
187 | 186 | #[tokio::main] |
188 | 187 | async fn main() -> Result<()> { |
189 | 188 | let start_time = Instant::now(); |
@@ -232,20 +231,10 @@ async fn main() -> Result<()> { |
232 | 231 | } |
233 | 232 |
|
234 | 233 | fn load_configs(start_time: Instant) -> (AwsConfig, Arc<Config>) { |
235 | | - // First load the configuration |
236 | | - let aws_config = AwsConfig { |
237 | | - region: env::var("AWS_DEFAULT_REGION").unwrap_or("us-east-1".to_string()), |
238 | | - aws_access_key_id: env::var("AWS_ACCESS_KEY_ID").unwrap_or_default(), |
239 | | - aws_secret_access_key: env::var("AWS_SECRET_ACCESS_KEY").unwrap_or_default(), |
240 | | - aws_session_token: env::var("AWS_SESSION_TOKEN").unwrap_or_default(), |
241 | | - aws_container_credentials_full_uri: env::var("AWS_CONTAINER_CREDENTIALS_FULL_URI") |
242 | | - .unwrap_or_default(), |
243 | | - aws_container_authorization_token: env::var("AWS_CONTAINER_AUTHORIZATION_TOKEN") |
244 | | - .unwrap_or_default(), |
245 | | - function_name: env::var("AWS_LAMBDA_FUNCTION_NAME").unwrap_or_default(), |
246 | | - sandbox_init_time: start_time, |
247 | | - }; |
248 | | - let lambda_directory = env::var("LAMBDA_TASK_ROOT").unwrap_or_else(|_| "/var/task".to_string()); |
| 234 | + // First load the AWS configuration |
| 235 | + let aws_config = AwsConfig::from_env(start_time); |
| 236 | + let lambda_directory: String = |
| 237 | + env::var("LAMBDA_TASK_ROOT").unwrap_or_else(|_| "/var/task".to_string()); |
249 | 238 | let config = match config::get_config(Path::new(&lambda_directory), &aws_config.region) { |
250 | 239 | Ok(config) => Arc::new(config), |
251 | 240 | Err(_e) => { |
@@ -630,7 +619,7 @@ fn setup_tag_provider( |
630 | 619 | account_id: &str, |
631 | 620 | ) -> Arc<TagProvider> { |
632 | 621 | let function_arn = |
633 | | - build_function_arn(account_id, &aws_config.region, &aws_config.function_name); |
| 622 | + build_lambda_function_arn(account_id, &aws_config.region, &aws_config.function_name); |
634 | 623 | let metadata_hash = hash_map::HashMap::from([( |
635 | 624 | lambda::tags::FUNCTION_ARN_KEY.to_string(), |
636 | 625 | function_arn.clone(), |
|
0 commit comments