Skip to content

Commit

Permalink
Add example.
Browse files Browse the repository at this point in the history
  • Loading branch information
buildwithzephyr committed Jan 7, 2024
1 parent 66686c3 commit 5a81670
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ retry = "2.0.0"
name = "postgres"
required-features = ["postgres"]

[[example]]
name = "localstack"
required-features = ["localstack"]

[[example]]
name = "neo4j"
required-features = ["neo4j"]
Expand Down
34 changes: 34 additions & 0 deletions examples/localstack.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use testcontainers_modules::{localstack::LocalStack, testcontainers::clients::Cli};
use aws_config::{meta::region::RegionProviderChain, BehaviorVersion};
use aws_sdk_s3 as s3;

#[tokio::main]
async fn main() -> Result<(), s3::Error> {
let docker = Cli::default();
let image = LocalStack::default()
.with_environment_variable("SERVICES", "s3");
let container = docker.run(image);
let host_port = container.get_host_port_ipv4(4566);

// Set up AWS client
let endpoint_url = format!("http://127.0.0.1:{host_port}");
let region_provider = RegionProviderChain::default_provider().or_else("us-east-1");
// let creds = s3::config::Credentials::new("minioadmin", "minioadmin", None, None, "test");
let config = aws_config::defaults(BehaviorVersion::v2023_11_09())
.region(region_provider)
.endpoint_url(endpoint_url)
.load()
.await;

let client = s3::Client::new(&config);

client.create_bucket().bucket("example-bucket").send().await?;

let list_buckets_output = client.list_buckets().send().await?;
assert!(list_buckets_output.buckets.is_some());
let buckets_list = list_buckets_output.buckets.unwrap();
assert_eq!(1, buckets_list.len());
assert_eq!("example-bucket", buckets_list[0].name.as_ref().unwrap());

Ok(())
}

0 comments on commit 5a81670

Please sign in to comment.