Created
June 7, 2020 14:11
-
-
Save BrianKopp/749c1c4b0a4ed3d750e680a0ce93d90c to your computer and use it in GitHub Desktop.
RustRusotoRocket_DynamoGetItem
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
extern crate rusoto_dynamodb; | |
use rusoto_dynamodb::*; | |
async fn dynamo_get_user(client: &DynamoDbClient, table_name: String, id: String) -> Result<User, &'static str> { | |
let mut get_key = HashMap::new(); | |
get_key.insert( | |
"id".to_string(), | |
AttributeValue { | |
s: Some(id.to_string()), | |
..Default::default() | |
}, | |
); | |
let input = GetItemInput{ | |
table_name: table_name, | |
key: get_key, | |
..Default::default() | |
}; | |
match client.get_item(input).await { | |
Err(error) => { | |
println!("Error: {:?}", error); | |
Err("error calling dynamo") | |
}, | |
Ok(output) => { | |
let item = match output.item { | |
None => { | |
println!("no item present"); | |
return Err("error, no item present") | |
}, | |
Some(i) => i | |
}; | |
Ok(User::from_map(item).unwrap()) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment