Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust: ec2 autoscaling scenario #5367

Merged
merged 10 commits into from
Oct 5, 2023
73 changes: 66 additions & 7 deletions .doc_gen/metadata/auto-scaling_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ auto-scaling_Hello:
Rust:
versions:
- sdk_version: 1
github: rust_dev_preview/examples/autoscaling
github: rust_dev_preview/examples/auto-scaling
excerpts:
- description:
snippet_tags:
Expand Down Expand Up @@ -101,7 +101,7 @@ auto-scaling_CreateAutoScalingGroup:
Rust:
versions:
- sdk_version: 1
github: rust_dev_preview/examples/autoscaling
github: rust_dev_preview/examples/auto-scaling
excerpts:
- description:
snippet_tags:
Expand Down Expand Up @@ -162,15 +162,14 @@ auto-scaling_DeleteAutoScalingGroup:
- sdk_version: 3
github: python/example_code/auto-scaling
excerpts:
- description: Update the minimum size of an Auto Scaling group to zero, terminate all
instances in the group, and delete the group.
- description: Update the minimum size of an Auto Scaling group to zero, terminate all instances in the group, and delete the group.
snippet_tags:
- python.cross_service.resilient_service.AutoScaler.decl
- python.cross_service.resilient_service.auto-scaling.DeleteAutoScalingGroup
Rust:
versions:
- sdk_version: 1
github: rust_dev_preview/examples/autoscaling
github: rust_dev_preview/examples/auto-scaling
excerpts:
- description:
snippet_tags:
Expand Down Expand Up @@ -237,7 +236,7 @@ auto-scaling_DescribeAutoScalingGroups:
Rust:
versions:
- sdk_version: 1
github: rust_dev_preview/examples/autoscaling
github: rust_dev_preview/examples/auto-scaling
excerpts:
- description:
snippet_tags:
Expand Down Expand Up @@ -304,7 +303,7 @@ auto-scaling_UpdateAutoScalingGroup:
Rust:
versions:
- sdk_version: 1
github: rust_dev_preview/examples/autoscaling
github: rust_dev_preview/examples/auto-scaling
excerpts:
- description:
snippet_tags:
Expand Down Expand Up @@ -382,6 +381,15 @@ auto-scaling_TerminateInstanceInAutoScalingGroup:
- cpp.example_code.autoscaling.autoscaling_client
- cpp.example_code.autoscaling.terminate_instance_autoscaling_group1
- cpp.example_code.autoscaling.terminate_instance_autoscaling_group2
Rust:
versions:
- sdk_version: 1
github: rust_dev_preview/examples/auto-scaling
excerpts:
- description:
snippet_tags:
- rust.auto-scaling.scenario.terminate_some_instance
- rust.auto-scaling.scenario.get_group
services:
auto-scaling: {TerminateInstanceInAutoScalingGroup}
auto-scaling_SetDesiredCapacity:
Expand Down Expand Up @@ -444,6 +452,14 @@ auto-scaling_SetDesiredCapacity:
- cpp.example_code.autoscaling.autoscaling_client
- cpp.example_code.autoscaling.set_desired_capacity1
- cpp.example_code.autoscaling.set_desired_capacity2
Rust:
versions:
- sdk_version: 1
github: rust_dev_preview/examples/auto-scaling
excerpts:
- description:
snippet_tags:
- rust.auto-scaling.scenario.scale_desired_capacity
services:
auto-scaling: {SetDesiredCapacity}
auto-scaling_DescribeAutoScalingInstances:
Expand Down Expand Up @@ -506,6 +522,14 @@ auto-scaling_DescribeAutoScalingInstances:
- cpp.example_code.autoscaling.autoscaling_client
- cpp.example_code.autoscaling.describe_autoscaling_instances1
- cpp.example_code.autoscaling.describe_autoscaling_instances2
Rust:
versions:
- sdk_version: 1
github: rust_dev_preview/examples/auto-scaling
excerpts:
- description:
snippet_tags:
- rust.auto-scaling.scenario.list_instances
services:
auto-scaling: {DescribeAutoScalingInstances}
auto-scaling_DescribeScalingActivities:
Expand Down Expand Up @@ -568,6 +592,14 @@ auto-scaling_DescribeScalingActivities:
- cpp.example_code.autoscaling.autoscaling_client
- cpp.example_code.autoscaling.describe_scaling_activities1
- cpp.example_code.autoscaling.describe_scaling_activities2
Rust:
versions:
- sdk_version: 1
github: rust_dev_preview/examples/auto-scaling
excerpts:
- description:
snippet_tags:
- rust.auto-scaling.scenario.describe_scenario
services:
auto-scaling: {DescribeScalingActivities}
auto-scaling_EnableMetricsCollection:
Expand Down Expand Up @@ -630,6 +662,14 @@ auto-scaling_EnableMetricsCollection:
- cpp.example_code.autoscaling.autoscaling_client
- cpp.example_code.autoscaling.enable_metrics_collection1
- cpp.example_code.autoscaling.enable_metrics_collection2
Rust:
versions:
- sdk_version: 1
github: rust_dev_preview/examples/auto-scaling
excerpts:
- description:
snippet_tags:
- rust.auto-scaling.scenario.enable_metrics_collection
services:
auto-scaling: {EnableMetricsCollection}
auto-scaling_DisableMetricsCollection:
Expand Down Expand Up @@ -692,6 +732,14 @@ auto-scaling_DisableMetricsCollection:
- cpp.example_code.autoscaling.autoscaling_client
- cpp.example_code.autoscaling.disable_metrics_collection1
- cpp.example_code.autoscaling.disable_metrics_collection2
Rust:
versions:
- sdk_version: 1
github: rust_dev_preview/examples/auto-scaling
excerpts:
- description:
snippet_tags:
- rust.auto-scaling.scenario.disable_metrics_collection
services:
auto-scaling: {DisableMetricsCollection}
auto-scaling_AttachLoadBalancerTargetGroups:
Expand Down Expand Up @@ -792,6 +840,17 @@ auto-scaling_Scenario_GroupsAndInstances:
- description:
snippet_tags:
- cpp.example_code.autoscaling.groups_and_instances_scenario
Rust:
versions:
- sdk_version: 1
github: rust_dev_preview/examples/auto-scaling
excerpts:
- description:
snippet_files:
- rust_dev_preview/examples/auto-scaling/Cargo.toml
- rust_dev_preview/examples/auto-scaling/src/bin/scenario.rs
- rust_dev_preview/examples/auto-scaling/src/lib.rs
- rust_dev_preview/examples/auto-scaling/src/scenario.rs
services:
auto-scaling:
{
Expand Down
2 changes: 1 addition & 1 deletion rust_dev_preview/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
target/
Cargo.lock
Cargo.lock
2 changes: 1 addition & 1 deletion rust_dev_preview/examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [
"apigateway",
"apigatewaymanagement",
"applicationautoscaling",
"autoscaling",
"auto-scaling",
"autoscalingplans",
"batch",
"cloudformation",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
[package]
name = "autoscaling-code-examples"
version = "0.1.0"
authors = ["Doug Schwartz <dougsch@amazon.com>"]
authors = ["Doug Schwartz <dougsch@amazon.com>", "David Souther <dpsouth@amazon.com>"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-sdk-autoscaling = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-sdk-ec2 = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-types = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
tokio = { version = "1.20.1", features = ["full"] }
clap = { version = "~4.2", features = ["derive"] }
tracing-subscriber = { version = "0.3.15", features = ["env-filter"] }
anyhow = "1.0.75"
tracing = "0.1.37"
tokio-stream = "0.1.14"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--Generated by WRITEME on 2023-06-06 21:26:09.955174 (UTC)-->
<!--Generated by WRITEME on 2023-09-20 20:49:21.334873 (UTC)-->
# Auto Scaling code examples for the SDK for Rust

## Overview
Expand All @@ -12,7 +12,7 @@ Shows how to use the AWS SDK for Rust to work with Amazon EC2 Auto Scaling.

## ⚠ Important

* Running this code might result in charges to your AWS account.
* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing](https://aws.amazon.com/pricing/?aws-products-pricing.sort-by=item.additionalFields.productNameLowercase&aws-products-pricing.sort-order=asc&awsf.Free%20Tier%20Type=*all&awsf.tech-category=*all) and [Free Tier](https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc&awsf.Free%20Tier%20Types=*all&awsf.Free%20Tier%20Categories=*all).
* Running the tests might result in charges to your AWS account.
* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege).
* This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services).
Expand All @@ -24,21 +24,39 @@ Shows how to use the AWS SDK for Rust to work with Amazon EC2 Auto Scaling.

### Prerequisites

For prerequisites, see the [README](../README.md#Prerequisites) in the `rust_dev_preview` folder.
For prerequisites, see the [README](../../README.md#Prerequisites) in the `rust_dev_preview` folder.


<!--custom.prerequisites.start-->
<!--custom.prerequisites.end-->


### Get started

* [Hello Auto Scaling](src/bin/list-autoscaling-groups.rs#L24) (`DescribeAutoScalingGroups`)

### Single actions

Code excerpts that show you how to call individual service functions.

* [Create a group](src/bin/create-autoscaling-group.rs#L32) (`CreateAutoScalingGroup`)
* [Delete a group](src/bin/delete-autoscaling-group.rs#L32) (`DeleteAutoScalingGroup`)
* [Disable metrics collection for a group](src/scenario.rs#L608) (`DisableMetricsCollection`)
* [Enable metrics collection for a group](src/scenario.rs#L288) (`EnableMetricsCollection`)
* [Get information about groups](src/bin/list-autoscaling-groups.rs#L24) (`DescribeAutoScalingGroups`)
* [Get information about instances](src/scenario.rs#L529) (`DescribeAutoScalingInstances`)
* [Get information about scaling activities](src/scenario.rs#L393) (`DescribeScalingActivities`)
* [Set the desired capacity of a group](src/scenario.rs#L586) (`SetDesiredCapacity`)
* [Terminate an instance in a group](src/scenario.rs#L645) (`TerminateInstanceInAutoScalingGroup`)
* [Update a group](src/bin/update-autoscaling-group.rs#L32) (`UpdateAutoScalingGroup`)

### Scenarios

Code examples that show you how to accomplish a specific task by calling multiple
functions within the same service.

* [Manage groups and instances](README.md)

## Run the examples

### Instructions
Expand All @@ -47,14 +65,36 @@ Code excerpts that show you how to call individual service functions.
<!--custom.instructions.start-->
<!--custom.instructions.end-->

#### Hello Auto Scaling

This example shows you how to get started using Auto Scaling.



#### Manage groups and instances

This example shows you how to do the following:

* Create an Amazon EC2 Auto Scaling group with a launch template and Availability Zones, and get information about running instances.
* Enable Amazon CloudWatch metrics collection.
* Update the group's desired capacity and wait for an instance to start.
* Terminate an instance in the group.
* List scaling activities that occur in response to user requests and capacity changes.
* Get statistics for CloudWatch metrics, then clean up resources.

<!--custom.scenario_prereqs.auto-scaling_Scenario_GroupsAndInstances.start-->
<!--custom.scenario_prereqs.auto-scaling_Scenario_GroupsAndInstances.end-->


<!--custom.scenarios.auto-scaling_Scenario_GroupsAndInstances.start-->
<!--custom.scenarios.auto-scaling_Scenario_GroupsAndInstances.end-->

### Tests

⚠ Running tests might result in charges to your AWS account.


To find instructions for running these tests, see the [README](../README.md#Tests)
To find instructions for running these tests, see the [README](../../README.md#Tests)
in the `rust_dev_preview` folder.


Expand Down
Loading
Loading