Skip to main content

Crate postrust_lambda

Crate postrust_lambda 

Source
Expand description

Postrust Lambda library.

What the postrust-lambda binary is made of, for a Lambda binary of your own: one that serves routes of yours beside the API, added with postrust_server::Builder.

use axum::{routing::post, Router};
use postrust_lambda::postrust_server::{AppState, Builder, Host};
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), postrust_lambda::Error> {
    postrust_lambda::init_tracing();
    let hooks: Router<Arc<AppState>> = Router::new().route("/stripe", post(|| async { "ok" }));
    let app = Builder::new(postrust_lambda::config_from_env()?, Host::LAMBDA)
        .nest("/hooks", hooks)
        .build()
        .await?;
    postrust_lambda::run(app).await
}

Build the application before calling run, in the init phase rather than on the first request: the connection and the schema cache are paid for once per sandbox, and a database that cannot be reached fails the init – which Lambda reports and retries – instead of failing every invocation.

Re-exports§

pub use postrust_auth;
pub use postrust_core;
pub use postrust_response;
pub use postrust_server;
pub use postrust_sql;

Functions§

config_from_env
The configuration from the environment, sized for a Lambda sandbox.
init_tracing
Log as the server does: RUST_LOG if set, otherwise PGRST_LOG_LEVEL, as text or as JSON lines by PGRST_LOG_FORMAT.
run
Serve app to the Lambda runtime until the sandbox is shut down.

Type Aliases§

Error
The error a Lambda handler returns, as the runtime takes it. Error type that lambdas may result in