Skip to content

How to have errors returned by handler displayed in Cloudwatch #98

@hazel-ocean

Description

@hazel-ocean

Hey all, first off - thank you for the awesome runtime!

Second, I'm not able to see errors printed properly in my Cloudwatch Logs, just a generic 2019-03-29 18:12:23 INFO [lambda_runtime_core::runtime] Error response for ... accepted by Runtime API .

I think I might be missing some kind of impl or something, but I'm not sure - should I be expecting errors returned by main to be displayed in Cloudwatch?

Here's my basic structure

use derive_more::{Display, From};
use failure::Fail;
use lambda_runtime::error::{lambda, HandlerError, LambdaErrorExt};
use serde_derive::Deserialize;

#[derive(Debug, Display, From)]
pub enum Error {
    // exhaustive errors here
}

impl Fail for Error {}

impl From<Error> for HandlerError {
    fn from(err: Error) -> HandlerError {
        HandlerError::new(err)
    }
}

impl LambdaErrorExt for Error {
    fn error_type(&self) -> &str {
        match self {
            // ...
        }
    }
}

#[derive(Deserialize, Debug)]
#[serde(untagged)]
pub enum Events {
    // ...
}

pub fn handler(event: Events, _ctx: lambda_runtime::Context) -> Result<(), Error> {
  // ...
  Ok(())
}

fn main() -> Result<(), Error> {
    simple_logger::init_with_level(log::Level::Info)?;
    lambda!(handler);

    Ok(())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions