Making Amazon Web Services service requests 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).

Making Amazon Web Services service requests using the Amazon SDK for Rust

To programmatically access Amazon Web Services services, the Amazon SDK for Rust uses a client struct for each Amazon Web Services service. For example, if your application needs to access Amazon EC2, your application creates an Amazon EC2 client struct to interface with that service. You then use the service client to make requests to that Amazon Web Services service.

To make a request to an Amazon Web Services service, you must first create and configure a service client. For each Amazon Web Services service your code uses, it has its own crate and its own dedicated type for interacting with it. The client exposes one method for each API operation exposed by the service.

To interact with Amazon Web Services services in Amazon SDK for Rust, create a service-specific client, use its API methods with fluent builder-style chaining, and call send() to execute the request.

The Client exposes one method for each API operation exposed by the service. The return value of each of these methods is a "fluent builder", where different inputs for that API are added by builder-style function call chaining. After calling the service's methods, call send() to get a Future that will result in either a successful output or a SdkError. For more information on SdkError, see Handling errors in the Amazon SDK for Rust.

The following example demonstrates a basic operation using Amazon S3 to create a bucket in the us-west-2 Amazon Web Services Region:

let config = aws_config::defaults(BehaviorVersion::latest()) .load() .await; let s3 = aws_sdk_s3::Client::new(&config); let result = s3.create_bucket() // Set some of the inputs for the operation. .bucket("my-bucket") .create_bucket_configuration( CreateBucketConfiguration::builder() .location_constraint(aws_sdk_s3::types::BucketLocationConstraint::UsWest2) .build() ) // send() returns a Future that does nothing until awaited. .send() .await;

Each service crate has additional modules used for API inputs, such as the following:

  • The types module has structs or enums to provide more complex structured information.

  • The primitives module has simpler types for representing data such as date times or binary blobs.

See the API reference documentation for the service crate for more detailed crate organization and information. For example, the aws-sdk-s3 crate for the Amazon Simple Storage Service has several Modules. Two of which are: