Make requests - AWS SDK for Rust

Make requests

To make a request to an AWS service, you must first create a service client. For each AWS service your code uses, it has its own crate and its own Client for interacting with it.

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 Error handling.

The following example demonstrates a basic operation using Amazon S3 to create a bucket in the us-west-2 AWS 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: