pub struct DynamoDBClient { /* private fields */ }Expand description
Dynamodb client for host interfaces.
This client uses Momento’s host-provided AWS communication channel, which is kept hot at all times. When your Function has not run in several days or more, the channel is still hot and ready, keeping your Function invocations predictable even when your demand is unpredictable.
Implementations§
Source§impl DynamoDBClient
impl DynamoDBClient
Sourcepub fn new(credentials: &AwsCredentialsProvider) -> Self
pub fn new(credentials: &AwsCredentialsProvider) -> Self
Create a new DynamoDB client.
let client = DynamoDBClient::new(
&AwsCredentialsProvider::new(
"us-east-1",
build_environment_aws_credentials!()
)?
);Sourcepub fn get_item<V, E>(
&self,
table_name: impl Into<String>,
key: impl Into<Key>,
) -> Result<Option<V>, GetItemError<E>>
pub fn get_item<V, E>( &self, table_name: impl Into<String>, key: impl Into<Key>, ) -> Result<Option<V>, GetItemError<E>>
Get an item from a DynamoDB table.
Examples:
Custom bound types:
use momento_functions_host::aws::ddb::{AttributeValue, DynamoDBClient, DynamoDBError, GetItemError, Item};
/// Look up an item from a DynamoDB table and deserialize it into a MyStruct.
/// Returns None if the item does not exist.
fn get_my_struct(client: &DynamoDBClient, which_one: &str) -> Result<Option<MyStruct>, GetItemError<String>> {
client.get_item("my_table", ("some_attribute", which_one))
}
struct MyStruct {
some_attribute: String,
}
// Boilerplate to convert from dynamodb format
impl TryFrom<Item> for MyStruct {
type Error = String;
fn try_from(mut value: Item) -> Result<Self, Self::Error> {
Ok(Self {
some_attribute: value.attributes.remove("some_attribute").ok_or("missing some_attribute")?.try_into()?,
})
}
}Sourcepub fn get_item_raw(
&self,
table_name: impl Into<String>,
key: impl Into<Key>,
) -> Result<Option<Item>, DynamoDBError>
pub fn get_item_raw( &self, table_name: impl Into<String>, key: impl Into<Key>, ) -> Result<Option<Item>, DynamoDBError>
Get an item from a DynamoDB table.
Examples:
use momento_functions_host::aws::ddb::{DynamoDBClient, DynamoDBError, Item};
/// Read an item from a DynamoDB table "my_table" with a S key attribute "some_attribute".
fn get_some_item(client: &DynamoDBClient, which_one: &str) -> Result<Option<Item>, DynamoDBError> {
client.get_item_raw("my_table", ("some_attribute", which_one))
}Sourcepub fn put_item(
&self,
table_name: impl Into<String>,
item: impl Into<Item>,
) -> Result<(), DynamoDBError>
pub fn put_item( &self, table_name: impl Into<String>, item: impl Into<Item>, ) -> Result<(), DynamoDBError>
Put an item into a DynamoDB table.
Examples: Raw item:
client.put_item(
"my_table",
[
("some_attribute", "some S value"),
("some_other_attribute", "some other S value"),
]
)Custom bound types:
use momento_functions_host::aws::ddb::{AttributeValue, DynamoDBClient, DynamoDBError, Item};
/// Store an item in a DynamoDB table by serializing a MyStruct.
fn put_my_struct(client: &DynamoDBClient, which_one: MyStruct) -> Result<(), DynamoDBError> {
client.put_item("my_table", which_one)
}
struct MyStruct {
some_attribute: String,
}
// Boilerplate to convert into dynamodb format
impl From<MyStruct> for Item {
fn from(value: MyStruct) -> Self {
[
("some_attribute", AttributeValue::from(value.some_attribute)),
].into()
}
}Auto Trait Implementations§
impl !Freeze for DynamoDBClient
impl RefUnwindSafe for DynamoDBClient
impl Send for DynamoDBClient
impl Sync for DynamoDBClient
impl Unpin for DynamoDBClient
impl UnwindSafe for DynamoDBClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more