-
Notifications
You must be signed in to change notification settings - Fork 381
Closed
Description
EventBridgeEvent: missing field 'detail-type'
I've configured an EventBridge rule than triggers a lambda on a schedule, but I get a deserialization error on field 'detail-type' every time the lambda gets invoked.
CDK
new Rule(scope, 'MyRule', {
schedule: Schedule.cron({ hour: '0', minute: '5' }),
targets: [
new LambdaFunction(lambdaAlias, {
event: RuleTargetInput.fromObject({ myField: 'my value' })
})
]
})Lambda handler
use aws_lambda_events::eventbridge::EventBridgeEvent;
use lambda_runtime::tracing::{debug, info, init_default_subscriber};
use lambda_runtime::{Error, LambdaEvent, run, service_fn};
use serde::{Deserialize, Serialize};
use tokio::main;
#[derive(Debug, Serialize, Deserialize)]
struct MyPayload {
#[serde(rename = "myField")]
my_field: String
}
async fn handler(event: LambdaEvent<EventBridgeEvent<MyPayload>>) -> Result<(), Error> {
debug!(?event, "My lambda triggered");
let MyPayload { my_field } = event.payload.detail;
info!("My field was {}", my_field);
Ok(())
}
#[main]
async fn main() -> Result<(), Error> {
init_default_subscriber();
run(service_fn(handler)).await
}Error
{
"message": "Request payload deserialization into LambdaEvent<T> failed. The handler will not be called. Log at TRACE level to see the payload.",
"error": "DeserializeError { inner: Error { path: Path { segments: [] }, original: Error(\"missing field `detail-type`\", line: 1, column: 22) } }"
}Trace
{
"message": "raw JSON event received from Lambda",
"body": "{\"myField\":\"my value\"}"
}State of investigation
From what I understand reading the docs, it seems "detail-type" might not be present all the time, but EventBridgeEvent makes it mandatory, hence this error I guess. Did not find a way to set it manually either. Looks like a bug in EventBridgeEvent?
Can you confirm my suspicions? Or am I missing something?
Metadata
Metadata
Assignees
Labels
No labels