lambda-apigateway-response

Crates.iolambda-apigateway-response
lib.rslambda-apigateway-response
version0.1.1
sourcesrc
created_at2022-06-02 16:03:13.126427
updated_at2022-06-02 16:36:58.341434
descriptionResponse object for AWS Lambda with API Gateway
homepagehttps://github.com/glaceef
repositoryhttps://github.com/glaceef/lambda-apigateway-response
max_upload_size
id598930
size41,320
mwatanabe (glaceef)

documentation

https://docs.rs/lambda-apigateway-response/

README

lambda-apigateway-response   Crates Badge Docs Badge License: Apache License: MIT

A response object for aws-lambda-rust-runtime, when the lambda function integrated into API Gateway.

Example

use lambda_apigateway_response::{
    http::StatusCode,
    types::{
        Headers,
        MultiValueHeaders,
    },
    Response,
};
use lambda_runtime::{
    Error as LambdaError,
    LambdaEvent,
};
use serde_json::json;

type LambdaResult<T> = Result<T, LambdaError>;

async fn handler(
    _event: LambdaEvent<serde_json::Value>,
) -> LambdaResult<Response<serde_json::Value>> {
    let res = Response {
        status_code: StatusCode::OK,
        body: json!({
            "message": "Hello world!",
        }),
        headers: Headers::new(),
        multi_value_headers: MultiValueHeaders::new(),
        is_base64_encoded: true,
    };

    Ok(res)
}

#[tokio::main]
async fn main() -> LambdaResult<()> {
    let handler_fn = lambda_runtime::service_fn(handler);
    lambda_runtime::run(handler_fn).await?;

    Ok(())
}
Commit count: 3

cargo fmt