Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
max_width=120
unstable_features = true
imports_granularity = "Crate"
reorder_imports = true
edition = "2021"
53 changes: 5 additions & 48 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ exclude = ["examples"]
[dependencies]
http = "0.2"
hyper = { version = "0.14", features = ["client"] }
lambda-extension = "0.7.0"
lambda_http = "0.7.2"
tokio = { version = "1.20.0", features = [
tokio = { version = "1.24", features = [
"macros",
"io-util",
"sync",
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ build-LambdaAdapterLayerArm64:
DOCKER_BUILDKIT=1 docker build --build-arg TARGET_PLATFORM=linux/arm64 --build-arg ARCH=aarch64 -o $(ARTIFACTS_DIR)/extensions .

fmt:
cargo +nightly fmt --all
cargo fmt --all
34 changes: 26 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ use std::{
use encoding_rs::{Encoding, UTF_8};
use http::{
header::{HeaderName, HeaderValue},
Uri,
Method, StatusCode, Uri,
};
use hyper::{
body::HttpBody,
client::{Client, HttpConnector},
Body,
};
use lambda_extension::Extension;
use lambda_http::aws_lambda_events::serde_json;
pub use lambda_http::Error;
use lambda_http::{Body as LambdaBody, Request, RequestExt, Response};
Expand Down Expand Up @@ -137,13 +137,31 @@ impl Adapter {
pub fn register_default_extension(&self) {
// register as an external extension
tokio::task::spawn(async move {
match Extension::new().with_events(&[]).run().await {
Ok(_) => {}
Err(err) => {
tracing::error!(err = err, "extension terminated unexpectedly");
panic!("extension thread execution");
}
let aws_lambda_runtime_api: String =
env::var("AWS_LAMBDA_RUNTIME_API").unwrap_or_else(|_| "127.0.0.1:9001".to_string());
let client = hyper::Client::new();
let register_req = hyper::Request::builder()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're missing the User-Agent based on the environment variable that the lambda client injects for you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine. We want to track invokes, not extensions registration calls.

.method(Method::POST)
.uri(format!("http://{aws_lambda_runtime_api}/2020-01-01/extension/register"))
.header("Lambda-Extension-Name", "lambda-adapter")
.body(Body::from("{ \"events\": [] }"))
.unwrap();
let register_res = client.request(register_req).await.unwrap();
if register_res.status() != StatusCode::OK {
panic!("extension registration failure");
}
let next_req = hyper::Request::builder()
.method(Method::GET)
.uri(format!(
"http://{aws_lambda_runtime_api}/2020-01-01/extension/event/next"
))
.header(
"Lambda-Extension-Identifier",
register_res.headers().get("Lambda-Extension-Identifier").unwrap(),
)
.body(Body::empty())
.unwrap();
client.request(next_req).await.unwrap();
});
}

Expand Down
3 changes: 1 addition & 2 deletions tests/integ_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ use httpmock::{
Method::{DELETE, GET, POST, PUT},
MockServer,
};
use lambda_extension::Service;

use lambda_http::Body;
use lambda_web_adapter::{Adapter, AdapterOptions, Protocol};
use tower::Service;

#[test]
fn test_adapter_options_from_env() {
Expand Down