pub struct LambdaClient { /* private fields */ }Expand description
Lambda 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 LambdaClient
impl LambdaClient
Sourcepub fn new(credentials: &AwsCredentialsProvider) -> Self
pub fn new(credentials: &AwsCredentialsProvider) -> Self
Create a new Lambda client.
use momento_functions_wit::host::momento::host::aws_auth::AuthError;
fn f() -> Result<(), AuthError> {
let client = LambdaClient::new(
&AwsCredentialsProvider::new(
"us-east-1",
build_environment_aws_credentials!()
)?
);Sourcepub fn invoke<E: Encode>(
&self,
name: impl Into<LambdaName>,
payload: E,
) -> Result<InvokeResponse, InvokeError<E::Error>>
pub fn invoke<E: Encode>( &self, name: impl Into<LambdaName>, payload: E, ) -> Result<InvokeResponse, InvokeError<E::Error>>
Invoke a lambda function.
You can use strings, bytes, or structs that are Serializable.
Examples:
use momento_functions_host::aws::lambda::{InvokeError, LambdaClient};
use momento_functions_host::encoding::Json;;
// With a payload
client.invoke(
"my_lambda_function",
"hello world",
)?;
// With a payload and a qualifier
client.invoke(
("my_lambda_function", "v1"),
"hello world",
)?;
// Without a payload
client.invoke(
"my_lambda_function",
(),
)?;
// With literal bytes
client.invoke(
"my_lambda_function",
b"some literal bytes".to_vec(),
)?;With json-encoded payloads
use momento_functions_host::aws::lambda::{InvokeError, LambdaClient};
use momento_functions_host::encoding::Json;
#[derive(serde::Serialize)]
struct MyStruct {
hello: String
}
#[derive(serde::Deserialize)]
struct Reply {
message: String
}
// Just a request payload, encoded as JSON
client.invoke(
"my_lambda_function",
Json(MyStruct { hello: "hello".to_string() }),
)?;
// Request and response payload, both encoded as JSON
let Json(reply): Json<Reply> = client.invoke(
"my_lambda_function",
Json(MyStruct { hello: "hello".to_string() }),
)?
.extract()?;
let message = reply.message;Auto Trait Implementations§
impl !Freeze for LambdaClient
impl RefUnwindSafe for LambdaClient
impl Send for LambdaClient
impl Sync for LambdaClient
impl Unpin for LambdaClient
impl UnwindSafe for LambdaClient
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