【发布时间】:2019-08-06 09:16:41
【问题描述】:
我正在处理一个简单的 Lambda 函数,我想知道是否可以将客户端(这次是 dynamodb)传递给处理程序,因此我们不会为每个请求重新连接。
宏在这里定义:
https://docs.rs/lambda_http/0.1.1/lambda_http/macro.lambda.html3
到目前为止我的功能:
fn main() -> Result<(), Box<dyn Error>> {
simple_logger::init_with_level(log::Level::Debug)?;
info!("Starting up...");
let dynamodb_client = DynamoDbClient::new(Region::EuCentral1);
lambda!(router);
return Ok(());
}
fn router(req: Request, ctx: Context) -> Result<impl IntoResponse, HandlerError> {
let h_req = HReq {
http_path: req.uri().path(),
http_method: req.method(),
};
match h_req {
HReq {
http_path: "/login",
http_method: &Method::POST,
} => user_login(req, ctx),
_ => {
error!(
"Not supported http method or path {}, {}",
h_req.http_path, h_req.http_method
);
let mut resp = Response::default();
*resp.status_mut() = StatusCode::METHOD_NOT_ALLOWED;
Ok(resp)
}
}
}
是否可以将此宏扩展为具有第二个选项,以便我可以将客户端一直添加到实际与数据库对话的函数?
【问题讨论】:
-
哪个宏?您能否更具体地说明您的实际要求?没听懂,抱歉。
-
你看到问题中的链接了吗?
-
stackoverflow.com/help/how-to-ask : “但也将代码复制到问题本身。不是每个人都可以访问外部站点,并且链接可能会随着时间的推移而中断”请这样做。您还链接到宏的文档,而不是代码本身。
标签: http rust aws-lambda