Skip to content

docs(lambda-extension): update README #408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions lambda-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,32 @@
The code below creates a simple extension that's registered to every `INVOKE` and `SHUTDOWN` events, and logs them in CloudWatch.

```rust,no_run
use lambda_extension::{extension_fn, Error, NextEvent};
use log::LevelFilter;
use simple_logger::SimpleLogger;
use tracing::info;

async fn log_extension(event: NextEvent) -> Result<(), Error> {
match event {
NextEvent::Shutdown(event) => {
info!("{}", event);
use lambda_extension::{service_fn, Error, LambdaEvent, NextEvent};

async fn my_extension(event: LambdaEvent) -> Result<(), Error> {
match event.next {
NextEvent::Shutdown(_e) => {
// do something with the shutdown event
}
NextEvent::Invoke(event) => {
info!("{}", event);
NextEvent::Invoke(_e) => {
// do something with the invoke event
}
}
Ok(())
}

#[tokio::main]
async fn main() -> Result<(), Error> {
SimpleLogger::new().with_level(LevelFilter::Info).init().unwrap();
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.with_ansi(false)
.without_time()
.init();

let func = extension_fn(log_extension);
let func = service_fn(my_extension);
lambda_extension::run(func).await
}

```

## Deployment
Expand Down