Skip to content

Improvements in event compilation #659

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

Merged
merged 5 commits into from
May 28, 2023
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
9 changes: 9 additions & 0 deletions .github/workflows/build-events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ jobs:
with:
package: aws_lambda_events
toolchain: ${{ matrix.toolchain}}
check-event-features:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2

- name: Test individual event features
run: make check-event-features
44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,47 @@ invoke-integration-api-%:
curl -X POST -d '{"command": "hello"}' $(API_URL)/trait/post
curl -X POST -d '{"command": "hello"}' $(API_URL)/al2/post
curl -X POST -d '{"command": "hello"}' $(API_URL)/al2-trait/post

# Test individual event features to ensure optional dependencies
# are correctly loaded when all default features are disabled.
check-event-features:
cargo test --package aws_lambda_events --no-default-features --features activemq
cargo test --package aws_lambda_events --no-default-features --features alb
cargo test --package aws_lambda_events --no-default-features --features apigw
cargo test --package aws_lambda_events --no-default-features --features appsync
cargo test --package aws_lambda_events --no-default-features --features autoscaling
cargo test --package aws_lambda_events --no-default-features --features chime_bot
cargo test --package aws_lambda_events --no-default-features --features clientvpn
cargo test --package aws_lambda_events --no-default-features --features cloudwatch_events
cargo test --package aws_lambda_events --no-default-features --features cloudwatch_logs
cargo test --package aws_lambda_events --no-default-features --features code_commit
cargo test --package aws_lambda_events --no-default-features --features codebuild
cargo test --package aws_lambda_events --no-default-features --features codedeploy
cargo test --package aws_lambda_events --no-default-features --features codepipeline_cloudwatch
cargo test --package aws_lambda_events --no-default-features --features codepipeline_job
cargo test --package aws_lambda_events --no-default-features --features cognito
cargo test --package aws_lambda_events --no-default-features --features config
cargo test --package aws_lambda_events --no-default-features --features connect
cargo test --package aws_lambda_events --no-default-features --features dynamodb
cargo test --package aws_lambda_events --no-default-features --features ecr_scan
cargo test --package aws_lambda_events --no-default-features --features firehose
cargo test --package aws_lambda_events --no-default-features --features iam
cargo test --package aws_lambda_events --no-default-features --features iot
cargo test --package aws_lambda_events --no-default-features --features iot_1_click
cargo test --package aws_lambda_events --no-default-features --features iot_button
cargo test --package aws_lambda_events --no-default-features --features iot_deprecated
cargo test --package aws_lambda_events --no-default-features --features kafka
cargo test --package aws_lambda_events --no-default-features --features kinesis
cargo test --package aws_lambda_events --no-default-features --features kinesis_analytics
cargo test --package aws_lambda_events --no-default-features --features lambda_function_urls
cargo test --package aws_lambda_events --no-default-features --features lex
cargo test --package aws_lambda_events --no-default-features --features rabbitmq
cargo test --package aws_lambda_events --no-default-features --features s3
cargo test --package aws_lambda_events --no-default-features --features s3_batch_job
cargo test --package aws_lambda_events --no-default-features --features ses
cargo test --package aws_lambda_events --no-default-features --features sns
cargo test --package aws_lambda_events --no-default-features --features sqs
cargo test --package aws_lambda_events --no-default-features --features streams

fmt:
cargo +nightly fmt --all
57 changes: 27 additions & 30 deletions lambda-events/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aws_lambda_events"
version = "0.9.0"
version = "0.10.0"
description = "AWS Lambda event definitions"
authors = [
"Christian Legnitto <[email protected]>",
Expand All @@ -13,29 +13,26 @@ repository = "https://github.com/awslabs/aws-lambda-rust-runtime"
readme = "README.md"
keywords = ["lambda", "aws", "amazon", "events", "S3"]
categories = ["api-bindings", "encoding", "web-programming"]
edition = "2021"

[dependencies]
base64 = "0.21"
http = "0.2"
http-body = "0.4"
http-serde = "^1"
serde = "^1"
serde_derive = "^1"
http = { version = "0.2", optional = true }
http-body = { version = "0.4", optional = true }
http-serde = { version = "^1", optional = true }
serde = { version = "^1", features = ["derive"] }
serde_with = { version = "^3", features = ["json"], optional = true }
serde_json = "^1"
serde_dynamo = { version = "^4.1", optional = true }
bytes = { version = "1", features = ["serde"] }
bytes = { version = "1", features = ["serde"], optional = true }
chrono = { version = "0.4.23", default-features = false, features = [
"clock",
"serde",
"std",
] }
query_map = { version = "^0.6", features = ["serde", "url-query"] }
], optional = true }
query_map = { version = "^0.6", features = ["serde", "url-query"], optional = true }
flate2 = { version = "1.0.24", optional = true }

[dev-dependencies]
pretty_assertions = "1.3"

[features]
default = [
"activemq",
Expand Down Expand Up @@ -78,40 +75,40 @@ default = [
]

activemq = []
alb = []
apigw = []
alb = ["bytes", "http", "http-body", "http-serde", "query_map"]
apigw = ["bytes", "http", "http-body", "http-serde", "query_map"]
appsync = []
autoscaling = []
chime_bot = []
autoscaling = ["chrono"]
chime_bot = ["chrono"]
clientvpn = []
cloudwatch_events = []
cloudwatch_events = ["chrono"]
cloudwatch_logs = ["flate2"]
code_commit = []
codebuild = []
codedeploy = []
code_commit = ["chrono"]
codebuild = ["chrono"]
codedeploy = ["chrono"]
codepipeline = []
codepipeline_cloudwatch = []
codepipeline_cloudwatch = ["chrono"]
codepipeline_job = []
cognito = []
config = []
connect = []
dynamodb = ["streams", "serde_dynamo"]
dynamodb = ["chrono", "serde_dynamo", "streams"]
ecr_scan = []
firehose = []
firehose = ["chrono"]
iam = []
iot = ["iam"]
iot = ["bytes", "http", "http-body", "http-serde", "iam"]
iot_1_click = []
iot_button = []
iot_deprecated = ["iot"]
kafka = []
kinesis = []
kafka = ["chrono"]
kinesis = ["chrono"]
kinesis_analytics = ["kinesis"]
lambda_function_urls = []
lambda_function_urls = ["bytes", "http", "http-body", "http-serde"]
lex = []
rabbitmq = []
s3 = []
s3 = ["bytes", "chrono", "http", "http-body", "http-serde"]
s3_batch_job = ["s3"]
ses = []
sns = ["serde_with"]
ses = ["chrono"]
sns = ["chrono", "serde_with"]
sqs = ["serde_with"]
streams = []
11 changes: 7 additions & 4 deletions lambda-events/src/custom_serde/codebuild_time.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use chrono::{DateTime, TimeZone, Utc};
use serde::de::{Deserialize, Deserializer, Error as DeError, Visitor};
use serde::ser::Serializer;
use serde::{
de::{Deserializer, Error as DeError, Visitor},
Deserialize,
};
use std::fmt;

// Jan 2, 2006 3:04:05 PM
Expand All @@ -10,7 +13,7 @@ struct TimeVisitor;
impl<'de> Visitor<'de> for TimeVisitor {
type Value = DateTime<Utc>;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "valid codebuild time: {}", CODEBUILD_TIME_FORMAT)
}

Expand Down Expand Up @@ -74,7 +77,7 @@ mod tests {
#[serde(with = "str_time")]
pub date: TestTime,
}
let data = json!({
let data = serde_json::json!({
"date": "Sep 1, 2017 4:12:29 PM"
});

Expand All @@ -92,7 +95,7 @@ mod tests {
#[serde(with = "optional_time")]
pub date: Option<TestTime>,
}
let data = json!({
let data = serde_json::json!({
"date": "Sep 1, 2017 4:12:29 PM"
});

Expand Down
6 changes: 3 additions & 3 deletions lambda-events/src/custom_serde/float_unix_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ fn ne_timestamp<T: fmt::Display>(ts: T) -> SerdeError<T, u8> {
}

impl<V: fmt::Display, D: fmt::Display> fmt::Debug for SerdeError<V, D> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "ChronoSerdeError({})", self)
}
}

impl<V: fmt::Display, D: fmt::Display> fmt::Display for SerdeError<V, D> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
SerdeError::NonExistent { ref timestamp } => {
write!(f, "value is not a legal timestamp: {}", timestamp)
Expand Down Expand Up @@ -77,7 +77,7 @@ where
impl<'de> de::Visitor<'de> for SecondsFloatTimestampVisitor {
type Value = DateTime<Utc>;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("a unix timestamp as a float")
}

Expand Down
13 changes: 7 additions & 6 deletions lambda-events/src/custom_serde/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'de> Visitor<'de> for HeaderMapVisitor {
type Value = HeaderMap;

// Format a message stating what data this Visitor expects to receive.
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("lots of things can go wrong with HeaderMap")
}

Expand Down Expand Up @@ -81,7 +81,7 @@ impl<'de> Visitor<'de> for HeaderMapVisitor {
let mut map = HeaderMap::with_capacity(access.size_hint().unwrap_or(0));

if !self.is_human_readable {
while let Some((key, arr)) = access.next_entry::<Cow<str>, Vec<Cow<[u8]>>>()? {
while let Some((key, arr)) = access.next_entry::<Cow<'_, str>, Vec<Cow<'_, [u8]>>>()? {
let key = HeaderName::from_bytes(key.as_bytes())
.map_err(|_| de::Error::invalid_value(Unexpected::Str(&key), &self))?;
for val in arr {
Expand All @@ -91,7 +91,7 @@ impl<'de> Visitor<'de> for HeaderMapVisitor {
}
}
} else {
while let Some((key, val)) = access.next_entry::<Cow<str>, OneOrMore>()? {
while let Some((key, val)) = access.next_entry::<Cow<'_, str>, OneOrMore<'_>>()? {
let key = HeaderName::from_bytes(key.as_bytes())
.map_err(|_| de::Error::invalid_value(Unexpected::Str(&key), &self))?;
match val {
Expand Down Expand Up @@ -135,6 +135,7 @@ where
#[cfg(test)]
mod tests {
use super::*;
use serde::{Deserialize, Serialize};

#[test]
fn test_deserialize_missing_http_headers() {
Expand All @@ -143,7 +144,7 @@ mod tests {
#[serde(deserialize_with = "deserialize_headers", default)]
pub headers: HeaderMap,
}
let data = json!({
let data = serde_json::json!({
"not_headers": {}
});

Expand All @@ -161,7 +162,7 @@ mod tests {
#[serde(serialize_with = "serialize_multi_value_headers")]
headers: HeaderMap,
}
let data = json!({
let data = serde_json::json!({
"headers": {
"Accept": ["*/*"]
}
Expand All @@ -181,7 +182,7 @@ mod tests {
#[serde(deserialize_with = "deserialize_headers")]
headers: HeaderMap,
}
let data = json!({ "headers": null });
let data = serde_json::json!({ "headers": null });

let decoded: Test = serde_json::from_value(data).unwrap();
assert!(decoded.headers.is_empty());
Expand Down
11 changes: 6 additions & 5 deletions lambda-events/src/custom_serde/http_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct MethodVisitor;
impl<'de> Visitor<'de> for MethodVisitor {
type Value = Method;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "valid method name")
}

Expand Down Expand Up @@ -56,6 +56,7 @@ pub fn serialize_optional<S: Serializer>(method: &Option<Method>, ser: S) -> Res
#[cfg(test)]
mod tests {
use super::*;
use serde::{Deserialize, Serialize};

#[test]
fn test_http_method_serializer() {
Expand All @@ -64,7 +65,7 @@ mod tests {
#[serde(with = "crate::custom_serde::http_method")]
pub method: http::Method,
}
let data = json!({
let data = serde_json::json!({
"method": "DELETE"
});
let decoded: Test = serde_json::from_value(data.clone()).unwrap();
Expand All @@ -83,7 +84,7 @@ mod tests {
#[serde(default)]
pub method: Option<http::Method>,
}
let data = json!({
let data = serde_json::json!({
"method": "DELETE"
});
let decoded: Test = serde_json::from_value(data.clone()).unwrap();
Expand All @@ -92,11 +93,11 @@ mod tests {
let recoded = serde_json::to_value(decoded).unwrap();
assert_eq!(data, recoded);

let data = json!({ "method": null });
let data = serde_json::json!({ "method": null });
let decoded: Test = serde_json::from_value(data).unwrap();
assert_eq!(None, decoded.method);

let data = json!({});
let data = serde_json::json!({});
let decoded: Test = serde_json::from_value(data).unwrap();
assert_eq!(None, decoded.method);
}
Expand Down
Loading