forked from aws/aws-lambda-rust-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelloworld.rs
More file actions
33 lines (31 loc) · 1.07 KB
/
Copy pathhelloworld.rs
File metadata and controls
33 lines (31 loc) · 1.07 KB
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
27
28
29
30
31
32
33
use aws_lambda_events::{
apigw::{ApiGatewayProxyRequest, ApiGatewayProxyResponse},
http::HeaderMap,
};
use lambda_runtime::{service_fn, tracing, Error, LambdaEvent};
#[tokio::main]
async fn main() -> Result<(), Error> {
tracing::init_default_subscriber();
let func = service_fn(func);
lambda_runtime::spawn_graceful_shutdown_handler(|| async move {}).await;
lambda_runtime::run(func).await?;
Ok(())
}
async fn func(_event: LambdaEvent<ApiGatewayProxyRequest>) -> Result<ApiGatewayProxyResponse, Error> {
let mut headers = HeaderMap::new();
headers.insert("content-type", "text/html".parse().unwrap());
let resp = {
let mut response = ApiGatewayProxyResponse::default();
response.status_code = 200;
response.multi_value_headers = headers.clone();
response.is_base64_encoded = false;
response.body = Some("Hello world!".into());
response.headers = headers;
#[cfg(feature = "catch-all-fields")]
{
response.other = Default::default();
}
response
};
Ok(resp)
}