Skip to content

Commit e6a5219

Browse files
authored
Merge pull request #37 from aws-samples/dynamodb-erase
feat(store): erase DynamoDB client & bump SDK
2 parents d60e05c + ad0644b commit e6a5219

File tree

3 files changed

+42
-39
lines changed

3 files changed

+42
-39
lines changed

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ edition = "2021"
66

77
[dependencies]
88
async-trait = "0.1"
9-
aws-config = "0.4"
10-
aws-sdk-dynamodb = "0.4"
11-
aws-sdk-eventbridge = "0.4"
12-
aws-smithy-client = { version = "0.34", features = ["test-util"] }
13-
aws-smithy-http = "0.34"
14-
aws-types = "0.4"
9+
aws-config = "0.6"
10+
aws-sdk-dynamodb = "0.6"
11+
aws-sdk-eventbridge = "0.6"
12+
aws-smithy-client = { version = "0.36", features = ["test-util"] }
13+
aws-smithy-http = "0.36"
14+
aws-types = "0.6"
1515
futures = { version = "0.3", features = ["std"] }
1616
lambda_runtime = { version = "0.4", optional = true }
1717
lambda_http = { version = "0.4", optional = true }

src/event_bus/eventbridge/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ mod tests {
9696
async fn get_mock_config() -> Config {
9797
let cfg = aws_config::from_env()
9898
.region(Region::new("eu-west-1"))
99-
.credentials_provider(Credentials::from_keys("accesskey", "privatekey", None))
99+
.credentials_provider(Credentials::new(
100+
"accesskey",
101+
"privatekey",
102+
None,
103+
None,
104+
"dummy",
105+
))
100106
.load()
101107
.await;
102108

src/store/dynamodb/mod.rs

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,21 @@ use ext::AttributeValuesExt;
1717
/// We have to pass a generic type parameter `C` for the underlying client,
1818
/// restricted to something that implements the SmithyConnector trait so we can
1919
/// use it with both the actual AWS SDK client and a mock implementation.
20-
pub struct DynamoDBStore<C> {
21-
client: Client<C>,
20+
pub struct DynamoDBStore {
21+
client: Client,
2222
table_name: String,
2323
}
2424

25-
impl<C> DynamoDBStore<C>
26-
where
27-
C: aws_smithy_client::bounds::SmithyConnector,
28-
{
29-
pub fn new(client: Client<C>, table_name: String) -> DynamoDBStore<C> {
25+
impl DynamoDBStore {
26+
pub fn new(client: Client, table_name: String) -> DynamoDBStore {
3027
DynamoDBStore { client, table_name }
3128
}
3229
}
3330

34-
impl<C> Store for DynamoDBStore<C> where C: aws_smithy_client::bounds::SmithyConnector {}
31+
impl Store for DynamoDBStore {}
3532

3633
#[async_trait]
37-
impl<C> StoreGetAll for DynamoDBStore<C>
38-
where
39-
C: aws_smithy_client::bounds::SmithyConnector,
40-
{
34+
impl StoreGetAll for DynamoDBStore {
4135
/// Get all items
4236
#[instrument(skip(self))]
4337
async fn all(&self, next: Option<&str>) -> Result<ProductRange, Error> {
@@ -65,10 +59,7 @@ where
6559
}
6660

6761
#[async_trait]
68-
impl<C> StoreGet for DynamoDBStore<C>
69-
where
70-
C: aws_smithy_client::bounds::SmithyConnector,
71-
{
62+
impl StoreGet for DynamoDBStore {
7263
/// Get item
7364
#[instrument(skip(self))]
7465
async fn get(&self, id: &str) -> Result<Option<Product>, Error> {
@@ -89,10 +80,7 @@ where
8980
}
9081

9182
#[async_trait]
92-
impl<C> StorePut for DynamoDBStore<C>
93-
where
94-
C: aws_smithy_client::bounds::SmithyConnector,
95-
{
83+
impl StorePut for DynamoDBStore {
9684
/// Create or update an item
9785
#[instrument(skip(self))]
9886
async fn put(&self, product: &Product) -> Result<(), Error> {
@@ -109,10 +97,7 @@ where
10997
}
11098

11199
#[async_trait]
112-
impl<C> StoreDelete for DynamoDBStore<C>
113-
where
114-
C: aws_smithy_client::bounds::SmithyConnector,
115-
{
100+
impl StoreDelete for DynamoDBStore {
116101
/// Delete item
117102
#[instrument(skip(self))]
118103
async fn delete(&self, id: &str) -> Result<(), Error> {
@@ -168,14 +153,20 @@ mod tests {
168153
use super::*;
169154
use crate::Error;
170155
use aws_sdk_dynamodb::{Client, Config, Credentials, Region};
171-
use aws_smithy_client::test_connection::TestConnection;
156+
use aws_smithy_client::{erase::DynConnector, test_connection::TestConnection};
172157
use aws_smithy_http::body::SdkBody;
173158

174159
/// Config for mocking DynamoDB
175160
async fn get_mock_config() -> Config {
176161
let cfg = aws_config::from_env()
177162
.region(Region::new("eu-west-1"))
178-
.credentials_provider(Credentials::from_keys("accesskey", "privatekey", None))
163+
.credentials_provider(Credentials::new(
164+
"accesskey",
165+
"privatekey",
166+
None,
167+
None,
168+
"dummy",
169+
))
179170
.load()
180171
.await;
181172

@@ -203,7 +194,8 @@ mod tests {
203194
.body(SdkBody::from(r#"{"Items": []}"#))
204195
.unwrap(),
205196
)]);
206-
let client = Client::from_conf_conn(get_mock_config().await, conn.clone());
197+
let client =
198+
Client::from_conf_conn(get_mock_config().await, DynConnector::new(conn.clone()));
207199
let store = DynamoDBStore::new(client, "test".to_string());
208200

209201
// WHEN getting all items
@@ -229,7 +221,8 @@ mod tests {
229221
.body(SdkBody::from(r#"{"Items": [{"id": {"S": "1"}, "name": {"S": "test1"}, "price": {"N": "1.0"}}]}"#))
230222
.unwrap(),
231223
)]);
232-
let client = Client::from_conf_conn(get_mock_config().await, conn.clone());
224+
let client =
225+
Client::from_conf_conn(get_mock_config().await, DynConnector::new(conn.clone()));
233226
let store = DynamoDBStore::new(client, "test".to_string());
234227

235228
// WHEN getting all items
@@ -264,7 +257,8 @@ mod tests {
264257
))
265258
.unwrap(),
266259
)]);
267-
let client = Client::from_conf_conn(get_mock_config().await, conn.clone());
260+
let client =
261+
Client::from_conf_conn(get_mock_config().await, DynConnector::new(conn.clone()));
268262
let store = DynamoDBStore::new(client, "test".to_string());
269263

270264
// WHEN getting all items
@@ -293,7 +287,8 @@ mod tests {
293287
.body(SdkBody::from("{}"))
294288
.unwrap(),
295289
)]);
296-
let client = Client::from_conf_conn(get_mock_config().await, conn.clone());
290+
let client =
291+
Client::from_conf_conn(get_mock_config().await, DynConnector::new(conn.clone()));
297292
let store = DynamoDBStore::new(client, "test".to_string());
298293

299294
// WHEN deleting an item
@@ -318,7 +313,8 @@ mod tests {
318313
.body(SdkBody::from(r#"{"Item": {"id": {"S": "1"}, "name": {"S": "test1"}, "price": {"N": "1.0"}}}"#))
319314
.unwrap(),
320315
)]);
321-
let client = Client::from_conf_conn(get_mock_config().await, conn.clone());
316+
let client =
317+
Client::from_conf_conn(get_mock_config().await, DynConnector::new(conn.clone()));
322318
let store = DynamoDBStore::new(client, "test".to_string());
323319

324320
// WHEN getting an item
@@ -351,7 +347,8 @@ mod tests {
351347
.body(SdkBody::from(r#"{"Attributes": {"id": {"S": "1"}, "name": {"S": "test1"}, "price": {"N": "1.5"}}}"#))
352348
.unwrap(),
353349
)]);
354-
let client = Client::from_conf_conn(get_mock_config().await, conn.clone());
350+
let client =
351+
Client::from_conf_conn(get_mock_config().await, DynConnector::new(conn.clone()));
355352
let store = DynamoDBStore::new(client, "test".to_string());
356353
let product = Product {
357354
id: "1".to_string(),

0 commit comments

Comments
 (0)