LambdaContext

Trait LambdaContext 

Source
pub trait LambdaContext<Env, EventType>: Sized {
    // Required method
    fn from_env<'life0, 'async_trait>(
        env: &'life0 Env,
    ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

A trait of the Context type, required when using run_message_handler to execute the message handler.

All Context types must implement the implement the LambdaContext::from_env method for their corresponding Env type in order to use the Context with run_message_handler.

When implementing LambdaContext you must also specify the EventType that the Lambda expects to receive, e.g. SqsEvent.

Required Methods§

Source

fn from_env<'life0, 'async_trait>( env: &'life0 Env, ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

§Example
use anyhow::Result;
use cobalt_aws::lambda::{LambdaContext, SqsEvent};

/// Shared context we build up before invoking the lambda runner.
#[derive(Debug)]
pub struct Context {
    pub greeting: String,
}

#[async_trait]
impl LambdaContext<Env, SqsEvent> for Context {
    /// Initialise a shared context object from which will be
    /// passed to all instances of the message handler.
    async fn from_env(env: &Env) -> Result<Context> {
        Ok(Context {
            greeting: env.greeting.clone(),
        })
    }
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§