Skip to content

Commit 2dffdbe

Browse files
committed
Added code and tests for HTTP handler for VPC lattice
1 parent df594fe commit 2dffdbe

9 files changed

Lines changed: 425 additions & 17 deletions

File tree

lambda-events/src/event/vpc_lattice/v2.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::{
2-
custom_serde::{deserialize_headers, deserialize_nullish, http_method, serialize_multi_value_headers},
3-
encodings::Body,
4-
};
1+
use crate::custom_serde::{deserialize_headers, deserialize_nullish, http_method, serialize_multi_value_headers};
52
#[cfg(feature = "builders")]
63
use bon::Builder;
74
use http::{HeaderMap, Method};
@@ -47,7 +44,7 @@ pub struct VpcLatticeRequestV2 {
4744

4845
/// The request body
4946
#[serde(default)]
50-
pub body: Option<Body>,
47+
pub body: Option<String>,
5148

5249
/// Whether the body is base64 encoded
5350
#[serde(default, deserialize_with = "deserialize_nullish")]

lambda-http/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ categories = ["web-programming::http-server"]
1717
readme = "README.md"
1818

1919
[features]
20-
default = ["apigw_rest", "apigw_http", "apigw_websockets", "alb", "tracing"]
20+
default = ["apigw_rest", "apigw_http", "apigw_websockets", "alb", "vpc_lattice", "tracing"]
2121
apigw_rest = []
2222
apigw_http = []
2323
apigw_websockets = []
2424
alb = []
25+
vpc_lattice = []
2526
pass_through = []
2627
catch-all-fields = ["aws_lambda_events/catch-all-fields"]
2728
tracing = ["lambda_runtime/tracing"] # enables access to the Tracing utilities
@@ -53,7 +54,7 @@ url = "2.2"
5354
path = "../lambda-events"
5455
version = "1.1"
5556
default-features = false
56-
features = ["alb", "apigw"]
57+
features = ["alb", "apigw", "vpc_lattice"]
5758

5859
[dev-dependencies]
5960
axum-core = "0.5.4"

lambda-http/src/deserializer.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use aws_lambda_events::apigw::ApiGatewayProxyRequest;
77
use aws_lambda_events::apigw::ApiGatewayV2httpRequest;
88
#[cfg(feature = "apigw_websockets")]
99
use aws_lambda_events::apigw::ApiGatewayWebsocketProxyRequest;
10+
#[cfg(feature = "vpc_lattice")]
11+
use aws_lambda_events::vpc_lattice::VpcLatticeRequestV2;
12+
1013
use serde::{de::Error, Deserialize};
1114
use serde_json::value::RawValue;
1215

@@ -39,6 +42,10 @@ impl<'de> Deserialize<'de> for LambdaRequest {
3942
if let Ok(res) = serde_json::from_str::<ApiGatewayWebsocketProxyRequest>(data) {
4043
return Ok(LambdaRequest::WebSocket(res));
4144
}
45+
#[cfg(feature = "vpc_lattice")]
46+
if let Ok(res) = serde_json::from_str::<VpcLatticeRequestV2>(data) {
47+
return Ok(LambdaRequest::VpcLatticeV2(res));
48+
}
4249
#[cfg(feature = "pass_through")]
4350
if PASS_THROUGH_ENABLED {
4451
return Ok(LambdaRequest::PassThrough(data.to_string()));
@@ -136,6 +143,20 @@ mod tests {
136143
}
137144
}
138145

146+
#[test]
147+
fn test_deserialize_vpc_lattice() {
148+
let data =
149+
include_bytes!("../../lambda-events/src/fixtures/example-vpc-lattice-v2-request.json");
150+
151+
let req: LambdaRequest = serde_json::from_slice(data).expect("failed to deserialize vpc lattice data");
152+
match req {
153+
LambdaRequest::VpcLatticeV2(req) => {
154+
assert_eq!("arn:aws:vpc-lattice:ap-southeast-2:123456789012:targetgroup/tg-6d0ecf831eec9f09", req.request_context.target_group_arn);
155+
}
156+
other => panic!("unexpected request variant: {other:?}"),
157+
}
158+
}
159+
139160
#[test]
140161
#[cfg(feature = "pass_through")]
141162
fn test_deserialize_bedrock_agent() {

lambda-http/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
#![cfg_attr(docsrs, feature(doc_cfg))]
33
//#![deny(warnings)]
44
//! Enriches the `lambda` crate with [`http`](https://github.com/hyperium/http)
5-
//! types targeting AWS [ALB](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html), [API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html) REST and HTTP API lambda integrations.
5+
//! types targeting AWS
6+
//! [ALB](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html),
7+
//! [API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html),
8+
//! [VPC Lattice](https://docs.aws.amazon.com/vpc-lattice/latest/ug/lambda-functions.html) REST and HTTP API lambda integrations.
69
//!
710
//! This crate abstracts over all of these trigger events using standard [`http`](https://github.com/hyperium/http) types minimizing the mental overhead
811
//! of understanding the nuances and variation between trigger details allowing you to focus more on your application while also giving you to the maximum flexibility to

0 commit comments

Comments
 (0)