Example of using LogEntry
spirrello opened this issue · 0 comments
spirrello commented
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!