-
Notifications
You must be signed in to change notification settings - Fork 391
Expand file tree
/
Copy pathmain.rs
More file actions
26 lines (22 loc) · 969 Bytes
/
main.rs
File metadata and controls
26 lines (22 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use lambda_http::{run, service_fn, tracing, Body, Error, Request, Response};
/// This is the main body for the function.
/// Write your code inside it.
/// There are some code examples in the Runtime repository:
/// - <https://github.com/aws/aws-lambda-rust-runtime/tree/main/examples>
async fn function_handler(_event: Request) -> Result<Response<Body>, Error> {
// Extract some useful information from the request
// Return something that implements IntoResponse.
// It will be serialized to the right response event automatically by the runtime
let resp = Response::builder()
.status(200)
.header("content-type", "text/html")
.body("Hello AWS Lambda HTTP request".into())
.map_err(Box::new)?;
Ok(resp)
}
#[tokio::main]
async fn main() -> Result<(), Error> {
// required to enable CloudWatch error logging by the runtime
tracing::init_default_subscriber();
run(service_fn(function_handler)).await
}