Skip to content

Commit 693a839

Browse files
committed
Rename features to match AWS documentation.
Use the names present in the API GW documentation to differentiate the APIs. Signed-off-by: David Calavera <[email protected]>
1 parent a7be08c commit 693a839

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -374,27 +374,27 @@ fn main() -> Result<(), Box<Error>> {
374374

375375
## Feature flags in lambda_http
376376

377-
`lambda_http` is a wrapper for HTTP events coming from two different services, Amazon Load Balancer (ALB), and AWS Api Gateway (APIGW). AWS Api Gateway can also send events from three different endpoints, Proxy V1, Proxy V2, and WebSockets. `lambda_http` transforms events from all these sources into native `http::Request` objects, so you can incorporate Rust http semantics into your Lambda functions.
377+
`lambda_http` is a wrapper for HTTP events coming from two different services, Amazon Load Balancer (ALB), and Amazon Api Gateway (APIGW). Amazon Api Gateway can also send events from three different endpoints, Proxy V1, Proxy V2, and WebSockets. `lambda_http` transforms events from all these sources into native `http::Request` objects, so you can incorporate Rust HTTP semantics into your Lambda functions.
378378

379-
By default, `lambda_http` compiles your function to support any of those services, this increases the compile time of your function because we have to generate code for all the sources. In reality, you'll usually put a Lambda function only behind of those sources. You can choose which source to generate code for with feature flags.
379+
By default, `lambda_http` compiles your function to support any of those services. This increases the compile time of your function because we have to generate code for all the sources. In reality, you'll usually put a Lambda function only behind one of those sources. You can choose which source to generate code for with feature flags.
380380

381381
The available features flags for `lambda_http` are the following:
382382

383-
- `alb`: for events coming from Amazon Load Balancer.
384-
- `apigw_v1`: for events coming from API Gateway Proxy V1.
385-
- `apigw_v2`: for events coming from API Gateway Proxy V2.
386-
- `apigw_websockets`: for events coming from API Gateway WebSockets.
383+
- `alb`: for events coming from [Amazon Elastic Load Balancer](https://aws.amazon.com/elasticloadbalancing/).
384+
- `apigw_rest`: for events coming from [Amazon API Gateway Rest APIs](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-rest-api.html).
385+
- `apigw_http`: for events coming from [Amazon API Gateway HTTP APIs](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html).
386+
- `apigw_websockets`: for events coming from [Amazon API Gateway WebSockets](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api.html).
387387

388-
If you only want to support one of these sources, you can disable the default features, and enable only the source that you care about in your package's Cargo.toml file. Substitute the dependency line for `lambda_http` for the snippet below, changing the feature that you want to enable:
388+
If you only want to support one of these sources, you can disable the default features, and enable only the source that you care about in your package's `Cargo.toml` file. Substitute the dependency line for `lambda_http` for the snippet below, changing the feature that you want to enable:
389389

390390
```toml
391391
[dependencies.lambda_http]
392392
version = "0.5.3"
393393
default-features = false
394-
features = ["apigw_v1"]
394+
features = ["apigw_rest"]
395395
```
396396

397-
This will make your function to compile much faster.
397+
This will make your function compile much faster.
398398

399399
## Supported Rust Versions (MSRV)
400400

lambda-http/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ categories = ["web-programming::http-server"]
1313
readme = "../README.md"
1414

1515
[features]
16-
default = ["apigw_v1", "apigw_v2", "apigw_websockets", "alb"]
17-
apigw_v1 = []
18-
apigw_v2 = []
16+
default = ["apigw_rest", "apigw_http", "apigw_websockets", "alb"]
17+
apigw_rest = []
18+
apigw_http = []
1919
apigw_websockets = []
2020
alb = []
2121

lambda-http/src/request.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
use crate::ext::{PathParameters, QueryStringParameters, RawHttpPath, StageVariables};
77
#[cfg(feature = "alb")]
88
use aws_lambda_events::alb::{AlbTargetGroupRequest, AlbTargetGroupRequestContext};
9-
#[cfg(feature = "apigw_v1")]
9+
#[cfg(feature = "apigw_rest")]
1010
use aws_lambda_events::apigw::{ApiGatewayProxyRequest, ApiGatewayProxyRequestContext};
11-
#[cfg(feature = "apigw_v2")]
11+
#[cfg(feature = "apigw_http")]
1212
use aws_lambda_events::apigw::{ApiGatewayV2httpRequest, ApiGatewayV2httpRequestContext};
1313
#[cfg(feature = "apigw_websockets")]
1414
use aws_lambda_events::apigw::{ApiGatewayWebsocketProxyRequest, ApiGatewayWebsocketProxyRequestContext};
@@ -28,9 +28,9 @@ use std::{io::Read, mem};
2828
#[derive(Deserialize, Debug)]
2929
#[serde(untagged)]
3030
pub enum LambdaRequest {
31-
#[cfg(feature = "apigw_v1")]
31+
#[cfg(feature = "apigw_rest")]
3232
ApiGatewayV1(ApiGatewayProxyRequest),
33-
#[cfg(feature = "apigw_v2")]
33+
#[cfg(feature = "apigw_http")]
3434
ApiGatewayV2(ApiGatewayV2httpRequest),
3535
#[cfg(feature = "alb")]
3636
Alb(AlbTargetGroupRequest),
@@ -44,9 +44,9 @@ impl LambdaRequest {
4444
/// type of response the request origin expects.
4545
pub fn request_origin(&self) -> RequestOrigin {
4646
match self {
47-
#[cfg(feature = "apigw_v1")]
47+
#[cfg(feature = "apigw_rest")]
4848
LambdaRequest::ApiGatewayV1 { .. } => RequestOrigin::ApiGatewayV1,
49-
#[cfg(feature = "apigw_v2")]
49+
#[cfg(feature = "apigw_http")]
5050
LambdaRequest::ApiGatewayV2 { .. } => RequestOrigin::ApiGatewayV2,
5151
#[cfg(feature = "alb")]
5252
LambdaRequest::Alb { .. } => RequestOrigin::Alb,
@@ -61,10 +61,10 @@ impl LambdaRequest {
6161
#[derive(Debug)]
6262
pub enum RequestOrigin {
6363
/// API Gateway request origin
64-
#[cfg(feature = "apigw_v1")]
64+
#[cfg(feature = "apigw_rest")]
6565
ApiGatewayV1,
6666
/// API Gateway v2 request origin
67-
#[cfg(feature = "apigw_v2")]
67+
#[cfg(feature = "apigw_http")]
6868
ApiGatewayV2,
6969
/// ALB request origin
7070
#[cfg(feature = "alb")]
@@ -74,7 +74,7 @@ pub enum RequestOrigin {
7474
WebSocket,
7575
}
7676

77-
#[cfg(feature = "apigw_v2")]
77+
#[cfg(feature = "apigw_http")]
7878
fn into_api_gateway_v2_request(ag: ApiGatewayV2httpRequest) -> http::Request<Body> {
7979
let http_method = ag.request_context.http.method.clone();
8080
let raw_path = ag.raw_path.unwrap_or_default();
@@ -146,7 +146,7 @@ fn into_api_gateway_v2_request(ag: ApiGatewayV2httpRequest) -> http::Request<Bod
146146
req
147147
}
148148

149-
#[cfg(feature = "apigw_v1")]
149+
#[cfg(feature = "apigw_rest")]
150150
fn into_proxy_request(ag: ApiGatewayProxyRequest) -> http::Request<Body> {
151151
let http_method = ag.http_method;
152152
let raw_path = ag.path.unwrap_or_default();
@@ -357,10 +357,10 @@ fn apigw_path_with_stage(stage: &Option<String>, path: &str) -> String {
357357
#[serde(untagged)]
358358
pub enum RequestContext {
359359
/// API Gateway proxy request context
360-
#[cfg(feature = "apigw_v1")]
360+
#[cfg(feature = "apigw_rest")]
361361
ApiGatewayV1(ApiGatewayProxyRequestContext),
362362
/// API Gateway v2 request context
363-
#[cfg(feature = "apigw_v2")]
363+
#[cfg(feature = "apigw_http")]
364364
ApiGatewayV2(ApiGatewayV2httpRequestContext),
365365
/// ALB request context
366366
#[cfg(feature = "alb")]
@@ -374,9 +374,9 @@ pub enum RequestContext {
374374
impl<'a> From<LambdaRequest> for http::Request<Body> {
375375
fn from(value: LambdaRequest) -> Self {
376376
match value {
377-
#[cfg(feature = "apigw_v1")]
377+
#[cfg(feature = "apigw_rest")]
378378
LambdaRequest::ApiGatewayV1(ag) => into_proxy_request(ag),
379-
#[cfg(feature = "apigw_v2")]
379+
#[cfg(feature = "apigw_http")]
380380
LambdaRequest::ApiGatewayV2(ag) => into_api_gateway_v2_request(ag),
381381
#[cfg(feature = "alb")]
382382
LambdaRequest::Alb(alb) => into_alb_request(alb),
@@ -449,10 +449,10 @@ mod tests {
449449
}
450450

451451
#[test]
452-
fn deserializes_minimal_apigw_v2_request_events() {
452+
fn deserializes_minimal_apigw_http_request_events() {
453453
// from the docs
454454
// https://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-api-gateway-request
455-
let input = include_str!("../tests/data/apigw_v2_proxy_request_minimal.json");
455+
let input = include_str!("../tests/data/apigw_http_proxy_request_minimal.json");
456456
let result = from_str(input);
457457
assert!(
458458
result.is_ok(),
@@ -477,10 +477,10 @@ mod tests {
477477
}
478478

479479
#[test]
480-
fn deserializes_apigw_v2_request_events() {
480+
fn deserializes_apigw_http_request_events() {
481481
// from the docs
482482
// https://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-api-gateway-request
483-
let input = include_str!("../tests/data/apigw_v2_proxy_request.json");
483+
let input = include_str!("../tests/data/apigw_http_proxy_request.json");
484484
let result = from_str(input);
485485
assert!(
486486
result.is_ok(),
@@ -620,7 +620,7 @@ mod tests {
620620
}
621621

622622
#[test]
623-
fn deserialize_apigw_v2_sam_local() {
623+
fn deserialize_apigw_http_sam_local() {
624624
// manually generated from AWS SAM CLI
625625
// Steps to recreate:
626626
// * sam init
@@ -629,7 +629,7 @@ mod tests {
629629
// * Change the function code to return the Lambda event serialized
630630
// * sam local start-api
631631
// * Invoke the API
632-
let input = include_str!("../tests/data/apigw_v2_sam_local.json");
632+
let input = include_str!("../tests/data/apigw_http_sam_local.json");
633633
let result = from_str(input);
634634
assert!(
635635
result.is_ok(),

lambda-http/src/response.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use crate::request::RequestOrigin;
44
use aws_lambda_events::encodings::Body;
55
#[cfg(feature = "alb")]
66
use aws_lambda_events::event::alb::AlbTargetGroupResponse;
7-
#[cfg(any(feature = "apigw_v1", feature = "apigw_websockets"))]
7+
#[cfg(any(feature = "apigw_rest", feature = "apigw_websockets"))]
88
use aws_lambda_events::event::apigw::ApiGatewayProxyResponse;
9-
#[cfg(feature = "apigw_v2")]
9+
#[cfg(feature = "apigw_http")]
1010
use aws_lambda_events::event::apigw::ApiGatewayV2httpResponse;
1111
use http::{
1212
header::{CONTENT_TYPE, SET_COOKIE},
@@ -19,9 +19,9 @@ use serde::Serialize;
1919
#[derive(Serialize, Debug)]
2020
#[serde(untagged)]
2121
pub enum LambdaResponse {
22-
#[cfg(any(feature = "apigw_v1", feature = "apigw_websockets"))]
22+
#[cfg(any(feature = "apigw_rest", feature = "apigw_websockets"))]
2323
ApiGatewayV1(ApiGatewayProxyResponse),
24-
#[cfg(feature = "apigw_v2")]
24+
#[cfg(feature = "apigw_http")]
2525
ApiGatewayV2(ApiGatewayV2httpResponse),
2626
#[cfg(feature = "alb")]
2727
Alb(AlbTargetGroupResponse),
@@ -44,15 +44,15 @@ impl LambdaResponse {
4444
let status_code = parts.status.as_u16();
4545

4646
match request_origin {
47-
#[cfg(feature = "apigw_v1")]
47+
#[cfg(feature = "apigw_rest")]
4848
RequestOrigin::ApiGatewayV1 => LambdaResponse::ApiGatewayV1(ApiGatewayProxyResponse {
4949
body,
5050
status_code: status_code as i64,
5151
is_base64_encoded: Some(is_base64_encoded),
5252
headers: headers.clone(),
5353
multi_value_headers: headers,
5454
}),
55-
#[cfg(feature = "apigw_v2")]
55+
#[cfg(feature = "apigw_http")]
5656
RequestOrigin::ApiGatewayV2 => {
5757
// ApiGatewayV2 expects the set-cookies headers to be in the "cookies" attribute,
5858
// so remove them from the headers.

0 commit comments

Comments
 (0)