Creating a service client in the AWS SDK for Rust - AWS SDK for Rust

This is documentation for the developer preview release of the AWS SDK for Rust. Do not use it in production as it is subject to breaking changes.

Creating a service client in the AWS SDK for Rust

This section describes how to create a client, including one in a specific Region.

In most cases you'll want to create a client that uses the default search path, which looks for credentials and Region in the order described in Specifying your credentials and default Region. After it finds a value for an access key, secret key, or Region, it stops searching for that value.

You can also supply a Region with an argument to the client object. Most of the SDK for Rust code examples use the following construct, which searches for the Region in the search path described previously. If a Region isn't found, this sets the Region to us-east-1. SERVICENAME is the name of the service, such as s3 for Amazon Simple Storage Service (Amazon S3).

use aws_config::meta::region::RegionProviderChain; use aws_sdk_SERVICENAME::Client; let region_provider = RegionProviderChain::default_provider().or_else("us-east-1"); let config = aws_config::from_env().region(region_provider).load().await; let client = Client::new(&config);