forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rust: Update localstack and dynamodb-local examples for Guide updates. (
awsdocs#6760) * Rust: Update localstack and dynamodb-local examples for Guide updates.
- Loading branch information
1 parent
3291f20
commit b7888f9
Showing
6 changed files
with
76 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,34 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#![allow(clippy::result_large_err)] | ||
|
||
// snippet-start:[dynamodb.rust.list-tables-local] | ||
use aws_config::BehaviorVersion; | ||
use aws_sdk_dynamodb::{Client, Error}; | ||
|
||
/// Lists your tables in DynamoDB local. | ||
/// Lists your tables from a local DynamoDB instance by setting the SDK Config's | ||
/// endpoint_url and test_credentials. | ||
#[tokio::main] | ||
async fn main() -> Result<(), Error> { | ||
let config = aws_config::defaults(BehaviorVersion::latest()) | ||
async fn main() { | ||
tracing_subscriber::fmt::init(); | ||
|
||
// snippet-start:[dynamodb.rust.list-tables-local.client_config] | ||
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) | ||
// Override the endpoint in the config to use a local dynamodb server. | ||
.endpoint_url( | ||
// DynamoDB run locally uses port 8000 by default. | ||
"http://localhost:8000", | ||
) | ||
.build(); | ||
let dynamodb_local_config = aws_sdk_dynamodb::config::Builder::from(&config).build(); | ||
|
||
let client = Client::from_conf(dynamodb_local_config); | ||
let client = aws_sdk_dynamodb::Client::from_conf(dynamodb_local_config); | ||
// snippet-end:[dynamodb.rust.list-tables-local.client_config] | ||
|
||
let resp = client.list_tables().send().await?; | ||
|
||
println!("Found {} tables", resp.table_names().len()); | ||
for name in resp.table_names() { | ||
println!(" {}", name); | ||
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:?}"), | ||
} | ||
|
||
Ok(()) | ||
} | ||
// snippet-end:[dynamodb.rust.list-tables-local] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,11 @@ | |
[package] | ||
name = "localstack-example" | ||
version = "0.1.0" | ||
authors = ["Doug Schwartz <[email protected]>"] | ||
edition = "2021" | ||
|
||
[dependencies] | ||
aws-config = { version = "1.0.1", features = ["behavior-version-latest"] } | ||
aws-sdk-s3 = { version = "1.4.0" } | ||
aws-sdk-sqs = { version = "1.3.0" } | ||
tokio = { version = "1.20.1", features = ["full"] } | ||
http = "0.2" | ||
tracing-subscriber = { version = "0.3.15", features = ["env-filter"] } | ||
aws-config = { version = "1", features = ["behavior-version-latest"] } | ||
aws-sdk-s3 = { version = "1" } | ||
tokio = { version = "1", features = ["full"] } | ||
tracing-subscriber = { version = "0.3", features = ["env-filter"] } | ||
# snippet-end:[localstack.rust.use-localstack-cargo.toml] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# snippet-start:[localstack.rust.aws_config] | ||
[profile localstack] | ||
region=us-east-1 | ||
output=json | ||
endpoint_url = http://localhost:4566 | ||
# snippet-end:[localstack.rust.aws_config] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters