Skip to content

Commit

Permalink
Update scenario for new paginators
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther committed Oct 5, 2023
1 parent db17b8f commit 632153e
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions rust_dev_preview/examples/auto-scaling/src/scenario.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use aws_sdk_autoscaling::{
types::{Activity, AutoScalingGroup, LaunchTemplateSpecification},
};
use aws_sdk_ec2::types::RequestLaunchTemplateData;
use tokio_stream::StreamExt;
use tracing::trace;

const LAUNCH_TEMPLATE_NAME: &str = "SDK_Code_Examples_EC2_Autoscaling_template_from_Rust_SDK";
Expand Down Expand Up @@ -108,7 +107,7 @@ impl Display for AutoScalingScenarioDescription {
writeln!(
f,
"\t\t- {} Progress: {}% Status: {:?} End: {:?}",
activity.cause().unwrap_or("(Cause unknown)"),
activity.cause(),
activity.progress(),
activity.status_code(),
// activity.status_message().unwrap_or_default()
Expand Down Expand Up @@ -374,7 +373,7 @@ impl AutoScalingScenario {
.send()
.await;
match describe_group {
Ok(group) => match group.auto_scaling_groups.unwrap_or_default().first() {
Ok(group) => match group.auto_scaling_groups().first() {
Some(group) => {
if group.status() != Some("Delete in progress") {
errors.push(ScenarioError::with(format!(
Expand Down Expand Up @@ -410,13 +409,12 @@ impl AutoScalingScenario {
.await
.map(|s| {
s.auto_scaling_groups()
.unwrap_or_default()
.iter()
.map(|s| {
format!(
"{}: {}",
s.auto_scaling_group_name().unwrap_or_default().clone(),
s.status().unwrap_or_default().clone()
s.auto_scaling_group_name(),
s.status().unwrap_or_default()
)
})
.collect::<Vec<String>>()
Expand Down Expand Up @@ -478,10 +476,8 @@ impl AutoScalingScenario {
));
}

let auto_scaling_groups = describe_auto_scaling_groups
.unwrap()
.auto_scaling_groups
.unwrap_or_default();
let describe_auto_scaling_groups_output = describe_auto_scaling_groups.unwrap();
let auto_scaling_groups = describe_auto_scaling_groups_output.auto_scaling_groups();
let auto_scaling_group = auto_scaling_groups.first();

if auto_scaling_group.is_none() {
Expand Down Expand Up @@ -509,7 +505,7 @@ impl AutoScalingScenario {
.map_err(|e| {
ScenarioError::new("Failed to get autoscaling activities for group", &e)
})?;
let activities = describe_activities.activities.unwrap_or_default();
let activities = describe_activities.activities();
trace!(
"Waiting for no scaling found {} activities",
activities.len()
Expand Down Expand Up @@ -542,19 +538,22 @@ impl AutoScalingScenario {
// Ok(self.get_group().await?.instances.unwrap_or_default().map(|i| i.instance_id.clone().unwrap_or_default()).filter(|id| !id.is_empty()).collect())

// Alternatively, and for the sake of example, DescribeAutoScalingInstances returns a list that can be filtered by the client.
Ok(self
.autoscaling
self.autoscaling
.describe_auto_scaling_instances()
.into_paginator()
.items()
.send()
.filter(|i| i.is_ok())
.map(|i| i.unwrap())
.filter(|i| i.auto_scaling_group_name() == Some(self.auto_scaling_group_name.as_str()))
.map(|i| i.instance_id.clone().unwrap_or_default())
.filter(|id| !id.is_empty())
.collect::<Vec<String>>()
.await)
.try_collect()
.await
.map(|items| {
items
.into_iter()
.filter(|i| i.auto_scaling_group_name == self.auto_scaling_group_name)
.map(|i| i.instance_id)
.filter(|id| !id.is_empty())
.collect::<Vec<String>>()
})
.map_err(|err| ScenarioError::new("Failed to get list of auto scaling instances", &err))
}
// snippet-end:[rust.auto-scaling.scenario.list_instances]

Expand Down Expand Up @@ -655,14 +654,15 @@ impl AutoScalingScenario {
// snippet-start:[rust.auto-scaling.scenario.terminate_some_instance]
pub async fn terminate_some_instance(&self) -> Result<(), ScenarioError> {
// Retrieve a list of instances in the auto scaling group.
let instances = self.get_group().await?.instances.unwrap_or_default();
let auto_scaling_group = self.get_group().await?;
let instances = auto_scaling_group.instances();
// Or use other logic to find an instance to terminate.
let instance = instances.first();
if let Some(instance) = instance {
let termination = self
.ec2
.terminate_instances()
.instance_ids(instance.instance_id().unwrap_or_default())
.instance_ids(instance.instance_id())
.send()
.await;
if let Err(err) = termination {
Expand Down

0 comments on commit 632153e

Please sign in to comment.