These examples demonstrate how to perform several Amazon EC2 operations using the developer preview version of the AWS SDK for Rust.
Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides resizable computing capacity—literally, servers in Amazon's data centers—that you use to build and host your software systems.
- Lists the state of one or all of your instances (DescribeInstances)
- [Lists the regions enabled for your account] (src/bin/ec2-helloworld) (ListRegions)
- Lists the scheduled events for your instances (ListInstanceEvents)
- Enables monitoring on an instance (MonitorInstance)
- Reboots an instance (RebootInstance)
- Starts an instance (StartInstance)
- Stops an instance (StopInstance)
- We recommend that you grant this code least privilege, or at most the minimum permissions required to perform the task. For more information, see Grant Least Privilege in the AWS Identity and Access Management User Guide.
- This code has not been tested in all AWS Regions. Some AWS services are available only in specific Regions.
- Running this code might result in charges to your AWS account.
You must have an AWS account, and have configured your default credentials and AWS Region as described in https://github.com/awslabs/aws-sdk-rust.
This example lists the state of one or all of your Amazon EC2 instances
cargo run --bin describe-instances -- [-i INSTANCE-ID] [-d DEFAULT-REGION] [-v]
- INSTANCE-ID is the ID of an instance to describe. If this argument is not supplied, the state of all instances is shown.
- DEFAULT-REGION is optional name of a region, such as us-east-1. If this value is not supplied, the region defaults to us-west-2.
- -v display additional information.
This example describes the AWS Regions that are enabled for your account.
cargo run --bin ec2-helloworld -- [-d DEFAULT-REGION] [-v]
If this argument is not supplied, the state of all instances is shown.
- DEFAULT-REGION is optional name of a region, such as us-east-1. If this value is not supplied, the region defaults to us-west-2.
- -v display additional information.
This example shows the scheduled events for the Amazon Elastic Compute Cloud (Amazon EC2) instances in the Region.
cargo run --bin list-all-instance-events -- [-d DEFAULT-REGION] [-v]
- DEFAULT-REGION is optional name of a region, such as us-east-1. If this value is not supplied, the region defaults to us-west-2.
- -v display additional information.
This example enables monitoring on an Amazon EC2 instance.
cargo run --bin monitor-instance -- -i INSTANCE-ID [-d DEFAULT-REGION] [-v]
- INSTANCE-ID is the ID of an instance to monitor. If this argument is not supplied, the state of all instances is shown.
- DEFAULT-REGION is optional name of a region, such as us-east-1. If this value is not supplied, the region defaults to us-west-2.
- -v display additional information.
This example reboots an Amazon EC2 instance.
cargo run --bin reboot-instance -- -i INSTANCE-ID [-d DEFAULT-REGION] [-v]
- INSTANCE-ID is the ID of an instance to reboot. If this argument is not supplied, the state of all instances is shown.
- DEFAULT-REGION is optional name of a region, such as us-east-1. If this value is not supplied, the region defaults to us-west-2.
- -v display additional information.
This example starts an Amazon EC2 instance.
cargo run --bin start-instance -- -i INSTANCE-ID [-d DEFAULT-REGION] [-v]
- INSTANCE-ID is the ID of an instance to start. If this argument is not supplied, the state of all instances is shown.
- DEFAULT-REGION is optional name of a region, such as us-east-1. If this value is not supplied, the region defaults to us-west-2.
- -v display additional information.
This example stops an Amazon EC2 instance.
cargo run --bin stop-instance -- -i INSTANCE-ID [-d DEFAULT-REGION] [-v]
- INSTANCE-ID is the ID of an instance to stop. If this argument is not supplied, the state of all instances is shown.
- DEFAULT-REGION is optional name of a region, such as us-east-1. If this value is not supplied, the region defaults to us-west-2.
- -v display additional information.
- AWS SDK for Rust repo
- AWS SDK for Rust API Reference for Amazon EC2
- AWS SDK for Rust Developer Guide
To propose a new code example to the AWS documentation team, see CONTRIBUTING.md. The team prefers to create code examples that show broad scenarios rather than individual API calls.
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0