diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2023-10-17 21:17:55 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2023-10-17 22:32:21 -0400 |
| commit | 288205e302d9f6afa06b8602184e983d2080a5b6 (patch) | |
| tree | dfb307e8f3cb82d280e5a0392f11318194e09ef1 /src/autoscaling.rs | |
CLI tool for updating Route53 DNS for an ASG.
Diffstat (limited to 'src/autoscaling.rs')
| -rw-r--r-- | src/autoscaling.rs | 34 |
1 files changed, 34 insertions, 0 deletions
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<C>(aws_context: &C, name: &str) -> Result<AutoScalingGroup> +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) +} |
