Skip to content

there is no reactor running, must be called from the context of Tokio runtime #266

Closed
@gangliao

Description

@gangliao
use lambda::{handler_fn, Context};
use serde_json::Value;

type Error = Box<dyn std::error::Error + Sync + Send + 'static>;

#[tokio::main]
async fn main() -> Result<(), Error> {
    lambda::run(handler_fn(handler)).await?;
    Ok(())
}

async fn handler(event: Value, _: Context) -> Result<Value, Error> {
    Ok(event)
}

#[cfg(test)]
mod tests {
    use super::*;
    use serde_json::json;

    #[tokio::test]
    async fn handler_handles() {
        let event = json!({
            "answer": 42
        });
        assert_eq!(
            handler(event.clone(), Context::default())
                .await
                .expect("expected Ok(_) value"),
            event
        )
    }
}

Hi @softprops @leepa @bdonlan @endor @marcbowes ,

When I run the code you provided above in the Lambda function, I got the following error. How can I fix it?

START RequestId: 067ed0e7-d441-4ed2-a77c-38f9b90bc0b5 Version: $LATEST
thread 'main' panicked at 'there is no reactor running, must be called from the context of Tokio runtime', /home/gangliao/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.22/src/io/driver/mod.rs:202:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
END RequestId: 067ed0e7-d441-4ed2-a77c-38f9b90bc0b5
REPORT RequestId: 067ed0e7-d441-4ed2-a77c-38f9b90bc0b5	Duration: 193.80 ms	Billed Duration: 200 ms	Memory Size: 128 MB	Max Memory Used: 6 MB	
RequestId: 067ed0e7-d441-4ed2-a77c-38f9b90bc0b5 Error: Runtime exited with error: exit status 101
Runtime.ExitError

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions