Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

AWS SDK for Rust code examples for Amazon EC2

Purpose

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.

Code examples

⚠ Important

  • 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.

Running the code examples

Prerequisites

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.

describe-instances

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.

ec2-helloworld

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.

list-all-instance-events

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.

monitor-instance

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.

reboot-instance

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.

start-instance

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.

stop-instance

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.

Resources

Contributing

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