Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instrument LambdaHandler's' convert_event function #2684

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ where
}

/// Converts a `lambda_http::Request` into a `http::Request<hyper::Body>`
/// Issue: <https://github.com/awslabs/smithy-rs/issues/1125>
/// The body conversion would not be required if we were to tackle this issue:
/// <https://github.com/awslabs/smithy-rs/issues/1125>
///
/// While converting the event the [API Gateway Stage] portion of the URI
/// is removed from the uri that gets returned as a new `http::Request`.
/// is removed from the URI that gets returned as the new `http::Request`.
///
/// So, for example, if the `https://redacted.execute-api.us-east-1.amazonaws.com/prod/operation`
/// was hit, then the raw HTTP path is just `/operation`, since `prod` is the API Gateway stage.
///
/// [API Gateway Stage]: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-stages.html
fn convert_event(request: Request) -> HyperRequest {
Expand All @@ -59,24 +63,28 @@ fn convert_event(request: Request) -> HyperRequest {
let mut path = String::from(parts.uri.path());

if !raw_path.is_empty() && raw_path != path {
tracing::trace!(raw_path, path, "rewriting request URI to use raw HTTP path");
hlbarber marked this conversation as resolved.
Show resolved Hide resolved
path = raw_path;

let uri_parts: uri::Parts = parts.uri.into();
let path_and_query = uri_parts
.path_and_query
.expect("request URI does not have `PathAndQuery`");
.expect("request URI does not have `PathAndQuery`; please file a bug report under https://github.com/awslabs/smithy-rs/issues");
tracing::trace!(?path_and_query);

if let Some(query) = path_and_query.query() {
path.push('?');
path.push_str(query);
}

parts.uri = uri::Uri::builder()
.authority(uri_parts.authority.expect("request URI does not have authority set"))
.scheme(uri_parts.scheme.expect("request URI does not have scheme set"))
.authority(uri_parts.authority.expect("request URI does not have authority set; please file a bug report under https://github.com/awslabs/smithy-rs/issues"))
.scheme(uri_parts.scheme.expect("request URI does not have scheme set; please file a bug report under https://github.com/awslabs/smithy-rs/issues"))
.path_and_query(path)
.build()
.expect("unable to construct new URI");
.expect("unable to construct new URI; please file a bug report under https://github.com/awslabs/smithy-rs/issues");
} else {
tracing::trace!(raw_path, path, "not rewriting request URI");
}

let body = match body {
Expand Down