Crate armature_lambda

Crate armature_lambda 

Source
Expand description

§Armature Lambda

AWS Lambda runtime adapter for Armature applications.

This crate allows you to deploy Armature applications to AWS Lambda with API Gateway, ALB, or Lambda Function URLs.

§Quick Start

use armature::prelude::*;
use armature_lambda::LambdaRuntime;

#[controller("/")]
struct HelloController;

#[controller_impl]
impl HelloController {
    #[get("/")]
    async fn hello() -> &'static str {
        "Hello from Lambda!"
    }
}

#[module(controllers: [HelloController])]
struct AppModule;

#[tokio::main]
async fn main() -> Result<(), lambda_runtime::Error> {
    // Initialize tracing for CloudWatch
    armature_lambda::init_tracing();

    // Create Armature application
    let app = Application::create::<AppModule>();

    // Run on Lambda
    LambdaRuntime::new(app).run().await
}

§With AWS Services

use armature_lambda::LambdaRuntime;
use armature_aws::{AwsServices, AwsConfig};

#[tokio::main]
async fn main() -> Result<(), lambda_runtime::Error> {
    armature_lambda::init_tracing();

    // Initialize AWS services
    let aws = AwsServices::new(
        AwsConfig::from_env()
            .enable_dynamodb()
            .enable_s3()
            .build()
    ).await?;

    // Register in DI container
    let app = Application::create::<AppModule>();
    app.container().register(aws);

    LambdaRuntime::new(app).run().await
}

§Deployment

Build for Lambda with:

# Install cargo-lambda
cargo install cargo-lambda

# Build for Lambda
cargo lambda build --release

# Deploy
cargo lambda deploy

Re-exports§

pub use lambda_http;
pub use lambda_runtime;

Macros§

impl_request_handler
Macro to implement RequestHandler for Armature applications.

Structs§

LambdaConfig
Lambda runtime configuration.
LambdaRequest
Wrapper for Lambda HTTP requests.
LambdaResponse
Lambda HTTP response.
LambdaRuntime
Lambda runtime for Armature applications.

Enums§

LambdaError
Lambda runtime errors.

Functions§

init_tracing
Initialize tracing for Lambda/CloudWatch.
init_tracing_with_level
Initialize tracing with a custom log level.

Type Aliases§

Result
Result type for Lambda operations.