Amazon ECS examples using SDK for Rust - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Amazon ECS examples using SDK for Rust

The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for Rust with Amazon ECS.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.

Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.

Topics

Actions

The following code example shows how to use CreateCluster.

SDK for Rust
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

async fn make_cluster(client: &aws_sdk_ecs::Client, name: &str) -> Result<(), aws_sdk_ecs::Error> { let cluster = client.create_cluster().cluster_name(name).send().await?; println!("cluster created: {:?}", cluster); Ok(()) }
  • For API details, see CreateCluster in AWS SDK for Rust API reference.

The following code example shows how to use DeleteCluster.

SDK for Rust
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

async fn remove_cluster( client: &aws_sdk_ecs::Client, name: &str, ) -> Result<(), aws_sdk_ecs::Error> { let cluster_deleted = client.delete_cluster().cluster(name).send().await?; println!("cluster deleted: {:?}", cluster_deleted); Ok(()) }
  • For API details, see DeleteCluster in AWS SDK for Rust API reference.

The following code example shows how to use DescribeClusters.

SDK for Rust
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

async fn show_clusters(client: &aws_sdk_ecs::Client) -> Result<(), aws_sdk_ecs::Error> { let resp = client.list_clusters().send().await?; let cluster_arns = resp.cluster_arns(); println!("Found {} clusters:", cluster_arns.len()); let clusters = client .describe_clusters() .set_clusters(Some(cluster_arns.into())) .send() .await?; for cluster in clusters.clusters() { println!(" ARN: {}", cluster.cluster_arn().unwrap()); println!(" Name: {}", cluster.cluster_name().unwrap()); } Ok(()) }