https://github.com/chamilad/aws-rust-hello-world
Intro code samples for AWS Rust SDK
https://github.com/chamilad/aws-rust-hello-world
Last synced: 5 months ago
JSON representation
Intro code samples for AWS Rust SDK
- Host: GitHub
- URL: https://github.com/chamilad/aws-rust-hello-world
- Owner: chamilad
- License: apache-2.0
- Created: 2024-01-08T19:02:25.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-11T00:28:34.000Z (over 2 years ago)
- Last Synced: 2025-08-06T17:54:24.411Z (10 months ago)
- Language: Rust
- Size: 30.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rust AWS SDK examples
This repository contains some simple examples on using the Rust AWS SDK with a
few edge cases.
The credentials and the config are loaded from the default locations similar to
the other language SDKs. This is demonstrated in the
[`01_simple_client`](./01_simple_client/) example. Variations to this approach
are demonstrated in the other three examples.
This example uses the CloudTrail service as a specific scenario. However the
usage is more or less similar across the other services.
1. create a config
1. create the client using the config
1. make the API calls
Each service has the crate documentation for more details.
```rust
use aws_config::SdkConfig;
use aws_sdk_cloudtrail::operation::list_trails::ListTrailsOutput;
use aws_sdk_cloudtrail::{
Client, Error,
};
//...
// create a config
let shared_config: SdkConfig = aws_config::load_from_env().await;
// create the client using the config
let client: Client = Client::new(&shared_config);
// make the API calls
let req = client.list_trails();
let resp: ListTrailsOutput= req.send().await?;
```
The SDK needs an async runtime since almost all calls made by the SDK will be
blocking calls waiting on network calls, file reads etc. The example uses
`tokio` however AWS mentions that any runtime with a thread sleep
function can be used, something that I haven't tried yet.
```rust
#[tokio::main]
async fn main() -> Result<(), Error> {
//...
}
```
Additionally, the SDK internally uses `hyper` HTTP framework, which also seems
to be inter-changeable with the advanced client building APIs provided by the
SDK.