extern crate pretty_env_logger; extern crate spectral; extern crate rusoto_core; extern crate rusoto_dynamodb; extern crate rusoto_credential; extern crate testcontainers; extern crate dynamodb_testcontainer; use spectral::prelude::*; use testcontainers::*; use rusoto_core::Region; use rusoto_dynamodb::{ DynamoDb, DynamoDbClient, CreateTableInput, KeySchemaElement, AttributeDefinition, ProvisionedThroughput }; use rusoto_credential::StaticProvider; use rusoto_core::HttpClient; #[test] fn dynamodb_local_create_table() { let _ = pretty_env_logger::try_init(); let docker = clients::Cli::default(); let node = docker.run(dynamodb_testcontainer::DynamoDb::default()); let host_port = node.get_host_port(8000).unwrap(); let mut create_tables_input = CreateTableInput::default(); create_tables_input.table_name = "books".to_string(); let mut key_schema_input = KeySchemaElement::default(); key_schema_input.key_type = "HASH".to_string(); key_schema_input.attribute_name = "title".to_string(); create_tables_input.key_schema = vec![key_schema_input]; let mut att0 = AttributeDefinition::default(); att0.attribute_name = "title".to_string(); att0.attribute_type = "S".to_string(); create_tables_input.attribute_definitions = vec![att0]; let mut provisioned_throughput = ProvisionedThroughput::default(); provisioned_throughput.read_capacity_units = 5; provisioned_throughput.write_capacity_units = 5; create_tables_input.provisioned_throughput = provisioned_throughput; let dynamodb = build_dynamodb_client(host_port); let result = dynamodb.create_table(create_tables_input).sync(); assert_that(&result).is_ok(); } fn build_dynamodb_client(host_port: u32) -> DynamoDbClient { let credentials_provider = StaticProvider::new( "fakeKey".to_string(), "fakeSecret".to_string(), None, None); let dispatcher = HttpClient::new() .expect("could not create http client"); let region = Region::Custom { name: "dynamodb-local".to_string(), endpoint: format!("http://localhost:{}", host_port) }; DynamoDbClient::new_with(dispatcher, credentials_provider, region) }