From 288205e302d9f6afa06b8602184e983d2080a5b6 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Tue, 17 Oct 2023 21:17:55 -0400 Subject: CLI tool for updating Route53 DNS for an ASG. --- src/autoscaling.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/autoscaling.rs (limited to 'src/autoscaling.rs') diff --git a/src/autoscaling.rs b/src/autoscaling.rs new file mode 100644 index 0000000..6c96279 --- /dev/null +++ b/src/autoscaling.rs @@ -0,0 +1,34 @@ +use anyhow::anyhow; +use aws_sdk_autoscaling as autoscaling; +use aws_sdk_autoscaling::types::AutoScalingGroup; + +use crate::result::Result; +use crate::single::Single; + +pub trait AutoScaling { + fn autoscaling(&self) -> &autoscaling::Client; +} + +pub async fn asg_by_name(aws_context: &C, name: &str) -> Result +where + C: AutoScaling, +{ + let asg_resp = aws_context + .autoscaling() + .describe_auto_scaling_groups() + .auto_scaling_group_names(name) + .send() + .await?; + + let auto_scaling_groups = asg_resp.auto_scaling_groups().unwrap_or(&[]); + let auto_scaling_group = auto_scaling_groups + .iter() + .map(ToOwned::to_owned) + .single() + .ok_or(anyhow!( + "No unique autoscaling group found with name: {}", + name + ))?; + + Ok(auto_scaling_group) +} -- cgit v1.2.3