Skip to content

Commit b19a79e

Browse files
authored
Fix support for APIGW console requests (#657)
Test requests from the APIGW console don't include time epoch. This change makes that field to be deserialized with a default value in those cases. Signed-off-by: David Calavera <[email protected]>
1 parent 7c93265 commit b19a79e

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

lambda-events/src/event/apigw/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ where
107107
pub http_method: Method,
108108
#[serde(default)]
109109
pub request_time: Option<String>,
110+
#[serde(default)]
110111
pub request_time_epoch: i64,
111112
/// The API Gateway rest API Id
112113
#[serde(default)]
@@ -180,6 +181,7 @@ where
180181
pub domain_prefix: Option<String>,
181182
#[serde(default)]
182183
pub time: Option<String>,
184+
#[serde(default)]
183185
pub time_epoch: i64,
184186
pub http: ApiGatewayV2httpRequestContextHttpDescription,
185187
#[serde(skip_serializing_if = "Option::is_none")]
@@ -920,4 +922,14 @@ mod test {
920922
let reparsed: ApiGatewayV2CustomAuthorizerV2Request = serde_json::from_slice(output.as_bytes()).unwrap();
921923
assert_eq!(parsed, reparsed);
922924
}
925+
926+
#[test]
927+
#[cfg(feature = "apigw")]
928+
fn example_apigw_console_request() {
929+
let data = include_bytes!("../../fixtures/example-apigw-console-request.json");
930+
let parsed: ApiGatewayProxyRequest = serde_json::from_slice(data).unwrap();
931+
let output: String = serde_json::to_string(&parsed).unwrap();
932+
let reparsed: ApiGatewayProxyRequest = serde_json::from_slice(output.as_bytes()).unwrap();
933+
assert_eq!(parsed, reparsed);
934+
}
923935
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"body": "{\"test\":\"body\"}",
3+
"resource": "/{proxy+}",
4+
"path": "/path/to/resource",
5+
"httpMethod": "POST",
6+
"queryStringParameters": {
7+
"foo": "bar"
8+
},
9+
"pathParameters": {
10+
"proxy": "path/to/resource"
11+
},
12+
"stageVariables": {
13+
"baz": "qux"
14+
},
15+
"headers": {
16+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
17+
"Accept-Encoding": "gzip, deflate, sdch",
18+
"Accept-Language": "en-US,en;q=0.8",
19+
"Cache-Control": "max-age=0",
20+
"CloudFront-Forwarded-Proto": "https",
21+
"CloudFront-Is-Desktop-Viewer": "true",
22+
"CloudFront-Is-Mobile-Viewer": "false",
23+
"CloudFront-Is-SmartTV-Viewer": "false",
24+
"CloudFront-Is-Tablet-Viewer": "false",
25+
"CloudFront-Viewer-Country": "US",
26+
"Host": "1234567890.execute-api.{dns_suffix}",
27+
"Upgrade-Insecure-Requests": "1",
28+
"User-Agent": "Custom User Agent String",
29+
"Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)",
30+
"X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==",
31+
"X-Forwarded-For": "127.0.0.1, 127.0.0.2",
32+
"X-Forwarded-Port": "443",
33+
"X-Forwarded-Proto": "https"
34+
},
35+
"requestContext": {
36+
"accountId": "123456789012",
37+
"resourceId": "123456",
38+
"stage": "prod",
39+
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
40+
"identity": {
41+
"cognitoIdentityPoolId": null,
42+
"accountId": null,
43+
"cognitoIdentityId": null,
44+
"caller": null,
45+
"apiKey": null,
46+
"sourceIp": "127.0.0.1",
47+
"cognitoAuthenticationType": null,
48+
"cognitoAuthenticationProvider": null,
49+
"userArn": null,
50+
"userAgent": "Custom User Agent String",
51+
"user": null
52+
},
53+
"resourcePath": "/{proxy+}",
54+
"httpMethod": "POST",
55+
"apiId": "1234567890"
56+
}
57+
}

0 commit comments

Comments
 (0)