Connect to a local DynamoDB instance using an AWS SDK
The following code example shows how to override an endpoint URL to connect to a local development deployment of DynamoDB and an AWS SDK.
For more information, see DynamoDB Local.
- Rust
-
- SDK for Rust
-
/// Lists your tables from a local DynamoDB instance by setting the SDK Config's
/// endpoint_url and test_credentials.
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let config = aws_config::defaults(aws_config::BehaviorVersion::latest())
.test_credentials()
// DynamoDB run locally uses port 8000 by default.
.endpoint_url("http://localhost:8000")
.load()
.await;
let dynamodb_local_config = aws_sdk_dynamodb::config::Builder::from(&config).build();
let client = aws_sdk_dynamodb::Client::from_conf(dynamodb_local_config);
let list_resp = client.list_tables().send().await;
match list_resp {
Ok(resp) => {
println!("Found {} tables", resp.table_names().len());
for name in resp.table_names() {
println!(" {}", name);
}
}
Err(err) => eprintln!("Failed to list local dynamodb tables: {err:?}"),
}
}
For a complete list of AWS SDK developer guides and code examples, see
Using DynamoDB with an AWS SDK.
This topic also includes information about getting started and details about previous SDK versions.