Set up the right dependencies and bring the bits of a lambda_runtime example in
This commit is contained in:
parent
316c79fe1c
commit
bf1fb592e3
File diff suppressed because it is too large
Load Diff
|
@ -5,3 +5,9 @@ authors = ["R. Tyler Croy <rtyler@brokenco.de>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
deltalake = { git = "https://github.com/delta-io/delta-rs", branch = "main", features = ["s3"] }
|
||||||
|
lambda_runtime = "0.3"
|
||||||
|
log = "0.4"
|
||||||
|
pretty_env_logger = "0.4"
|
||||||
|
tokio = { version = "1.0", features = ["macros"]}
|
||||||
|
serde = { version = "1", features = ["rc", "derive"]}
|
||||||
|
|
51
src/main.rs
51
src/main.rs
|
@ -1,3 +1,50 @@
|
||||||
fn main() {
|
/*
|
||||||
println!("Hello, world!");
|
* The bulk of the application
|
||||||
|
*/
|
||||||
|
|
||||||
|
use deltalake::*;
|
||||||
|
use lambda_runtime::{handler_fn, Context, Error};
|
||||||
|
use log::*;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// This is also a made-up example. Requests come into the runtime as unicode
|
||||||
|
/// strings in json format, which can map to any structure that implements `serde::Deserialize`
|
||||||
|
/// The runtime pays no attention to the contents of the request payload.
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct Request {
|
||||||
|
command: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This is a made-up example of what a response structure may look like.
|
||||||
|
/// There is no restriction on what it can be. The runtime requires responses
|
||||||
|
/// to be serialized into json. The runtime pays no attention
|
||||||
|
/// to the contents of the response payload.
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct Response {
|
||||||
|
req_id: String,
|
||||||
|
msg: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), Error> {
|
||||||
|
pretty_env_logger::init();
|
||||||
|
info!("Initializing delta-s3-loader v{}", env!["CARGO_PKG_VERSION"]);
|
||||||
|
|
||||||
|
let func = handler_fn(my_handler);
|
||||||
|
lambda_runtime::run(func).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn my_handler(event: Request, ctx: Context) -> Result<Response, Error> {
|
||||||
|
// extract some useful info from the request
|
||||||
|
let command = event.command;
|
||||||
|
|
||||||
|
// prepare the response
|
||||||
|
let resp = Response {
|
||||||
|
req_id: ctx.request_id,
|
||||||
|
msg: format!("Command {} executed.", command),
|
||||||
|
};
|
||||||
|
|
||||||
|
// return `Response` (it will be serialized to JSON automatically by the runtime)
|
||||||
|
Ok(resp)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue