summaryrefslogtreecommitdiff
path: root/src/autoscaling.rs
blob: ea76dc02da10654866951c0596f24dedc0371a09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use anyhow::{bail, Result};
use aws_sdk_autoscaling as autoscaling;
use aws_sdk_autoscaling::types::AutoScalingGroup;

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 groups_resp = aws_context
        .autoscaling()
        .describe_auto_scaling_groups()
        .auto_scaling_group_names(name)
        .send()
        .await?;

    let mut groups = groups_resp.auto_scaling_groups().iter();
    let group = match (groups.next(), groups.next()) {
        (Some(group), None) => group,
        (None, _) => bail!("No autoscaling group found with name: {name}"),
        (Some(_), Some(_)) => bail!("Multiple autoscaling groups found with name: {name}"),
    };

    Ok(group.to_owned())
}