LambdaClient

Struct LambdaClient 

Source
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

Source

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!()
    )?
);
Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.