diff --git a/rust-runtime/aws-smithy-http-server/src/request/lambda.rs b/rust-runtime/aws-smithy-http-server/src/request/lambda.rs new file mode 100644 index 0000000000..c78e212726 --- /dev/null +++ b/rust-runtime/aws-smithy-http-server/src/request/lambda.rs @@ -0,0 +1,52 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +//! The [`lambda_http`] types included in [`http::Request`]s when [`LambdaHandler`](crate::routing::LambdaHandler) is +//! used. Each are given a [`FromParts`] implementation for easy use within handlers. + +use lambda_http::request::RequestContext; +#[doc(inline)] +pub use lambda_http::{ + aws_lambda_events::apigw::{ApiGatewayProxyRequestContext, ApiGatewayV2httpRequestContext}, + Context, +}; + +use super::{extension::MissingExtension, FromParts}; +use crate::Extension; + +impl
FromParts
for Context {
+ type Rejection = MissingExtension;
+
+ fn from_parts(parts: &mut http::request::Parts) -> Result >::from_parts(parts)?;
+ Ok(context)
+ }
+}
+
+impl FromParts for ApiGatewayProxyRequestContext {
+ type Rejection = MissingExtension;
+
+ fn from_parts(parts: &mut http::request::Parts) -> Result >::from_parts(parts)?;
+ if let RequestContext::ApiGatewayV1(context) = context {
+ Ok(context)
+ } else {
+ Err(MissingExtension)
+ }
+ }
+}
+
+impl FromParts for ApiGatewayV2httpRequestContext {
+ type Rejection = MissingExtension;
+
+ fn from_parts(parts: &mut http::request::Parts) -> Result >::from_parts(parts)?;
+ if let RequestContext::ApiGatewayV2(context) = context {
+ Ok(context)
+ } else {
+ Err(MissingExtension)
+ }
+ }
+}
diff --git a/rust-runtime/aws-smithy-http-server/src/request/mod.rs b/rust-runtime/aws-smithy-http-server/src/request/mod.rs
index efcf3c6041..6f3e0429ca 100644
--- a/rust-runtime/aws-smithy-http-server/src/request/mod.rs
+++ b/rust-runtime/aws-smithy-http-server/src/request/mod.rs
@@ -52,6 +52,9 @@ use crate::{rejection::any_rejections, response::IntoResponse};
pub mod connect_info;
pub mod extension;
+#[cfg(feature = "aws-lambda")]
+#[cfg_attr(docsrs, doc(cfg(feature = "aws-lambda")))]
+pub mod lambda;
#[doc(hidden)]
#[derive(Debug)]