summaryrefslogtreecommitdiff
path: root/src/autoscaling.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/autoscaling.rs')
-rw-r--r--src/autoscaling.rs34
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)
+}