Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Example of using LogEntry #126

Closed
spirrello opened this issue Nov 14, 2022 · 0 comments
Closed

Example of using LogEntry #126

spirrello opened this issue Nov 14, 2022 · 0 comments

Comments

@spirrello
Copy link

spirrello commented Nov 14, 2022

Hi,

Can you point me to an example of how to use this crate with LogEntry event? I'm trying to write a lambda that uses this event when a new log is sent to a log stream however it isn't clear to me on how to use this crate for this purpose. I'm new to Rust so this also doesn't help.

The error I'm getting from the compiler is the following:

error[E0277]: the trait bound `fn(LogEntry) -> Result<(), Box<(dyn StdError + Send + Sync + 'static)>> {function_handler}: Service<LambdaEvent<_>>` is not satisfied
   --> src/main.rs:18:9
    |
18  |     run(function_handler).await?;
    |     --- ^^^^^^^^^^^^^^^^ the trait `Service<LambdaEvent<_>>` is not implemented for fn item `fn(LogEntry) -> Result<(), Box<(dyn StdError + Send + Sync + 'static)>> {function_handler}`
    |     |
    |     required by a bound introduced by this call
    |
    = help: the following other types implement trait `Service<Request>`:
              <&'a mut S as Service<Request>>
              <&hyper::client::client::Client<C, B> as Service<Request<B>>>
              <AndThen<S, F> as Service<Request>>
              <Box<S> as Service<Request>>
              <BoxCloneService<T, U, E> as Service<T>>
              <BoxService<T, U, E> as Service<T>>
              <Either<A, B> as Service<Request>>
              <FutureService<F, S> as Service<R>>
            and 16 others
note: required by a bound in `run`
   --> /Users/stefano/.cargo/registry/src/github.com-1ecc6299db9ec823/lambda_runtime-0.7.0/src/lib.rs:231:8
    |
231 |     F: Service<LambdaEvent<A>>,
    |        ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `run`

This is where I'm currently at.

use aws_lambda_events::{cloudwatch_logs, event::cloudwatch_logs::LogEntry};
use lambda_runtime::{run, service_fn, Error, LambdaEvent};

#[tokio::main]
async fn function_handler(event: LogEntry) -> Result<(), Error> {
    Ok(())
}

#[tokio::main]
async fn main() -> Result<(), Error> {
    tracing_subscriber::fmt()
        .with_max_level(tracing::Level::INFO)
        .with_target(false)
        .without_time()
        .init();

    let func = service_fn(function_handler);
    lambda_runtime::run(function_handler).await?;
    Ok(())
}

Thanks in advance!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant