Creating a simple application using the Amazon SDK for Rust - Amazon SDK for Rust
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Creating a simple application using the Amazon SDK for Rust

You can get started quickly with Amazon SDK for Rust by following this tutorial for creating a simple application that calls an Amazon Web Services service.

Prerequisites

In order to use the Amazon SDK for Rust, you must have Rust and Cargo installed.

The following optional tools can be installed in your IDE to assist with code completion and troubleshooting.

Create your first SDK app

This procedure creates your first SDK for Rust application that lists your DynamoDB tables.

  1. In a terminal or console window, navigate to a location on your computer where you want to create the app.

  2. Run the following command to create a hello_world directory and populate it with a skeleton Rust project:

    $ cargo new hello_world --bin
  3. Navigate into the hello_world directory and use the following command to add the required dependencies to the app:

    $ cargo add aws-config aws-sdk-dynamodb tokio --features tokio/full

    These dependencies include the SDK crates that provide configuration features and support for DynamoDB, including the tokio crate, which is used to implement asynchronous I/O operations.

    Note

    Unless you use a feature like tokio/full Tokio will not provide an async runtime. The SDK for Rust requires an async runtime.

  4. Update main.rs in the src directory to contain the following code.

    use aws_config::meta::region::RegionProviderChain; use aws_config::BehaviorVersion; use aws_sdk_dynamodb::{Client, Error}; /// Lists your DynamoDB tables in the default Region or us-east-1 if a default Region isn't set. #[tokio::main] async fn main() -> Result<(), Error> { let region_provider = RegionProviderChain::default_provider().or_else("us-east-1"); let config = aws_config::defaults(BehaviorVersion::latest()) .region(region_provider) .load() .await; let client = Client::new(&config); let resp = client.list_tables().send().await?; println!("Tables:"); let names = resp.table_names(); for name in names { println!(" {}", name); } println!(); println!("Found {} tables", names.len()); Ok(()) }
    Note

    This example only displays the first page of results. See Using paginated results in the Amazon SDK for Rust to learn how to handle multiple pages of results.

  5. Run the program:

    $ cargo run

    You should see a list of your table names.