File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed
integration-kinesis-to-lambda Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ use aws_lambda_events:: event:: kinesis:: KinesisEvent ;
2
+ use lambda_runtime:: { run, service_fn, Error , LambdaEvent } ;
3
+
4
+ static UNDEFINED : & str = "undefined" ;
5
+
6
+ async fn function_handler ( event : LambdaEvent < KinesisEvent > ) -> Result < ( ) , Error > {
7
+
8
+ if event. payload . records . is_empty ( ) {
9
+ tracing:: info!( "No records found. Exiting." ) ;
10
+ return Ok ( ( ) ) ;
11
+ }
12
+
13
+ event. payload . records . iter ( ) . for_each ( |record| {
14
+
15
+ tracing:: info!( "EventId: {}" , record. event_id. as_deref( ) . unwrap_or( UNDEFINED ) ) ;
16
+
17
+ let record_data = std:: str:: from_utf8 ( & record. kinesis . data ) ;
18
+
19
+ match record_data {
20
+ Ok ( data) => {
21
+ // log the record data
22
+ tracing:: info!( "Data: {}" , data) ;
23
+ }
24
+ Err ( e) => {
25
+ tracing:: error!( "Error: {}" , e) ;
26
+ }
27
+ }
28
+ } ) ;
29
+
30
+ tracing:: info!(
31
+ "Successfully processed {} records" ,
32
+ event. payload. records. len( )
33
+ ) ;
34
+
35
+ Ok ( ( ) )
36
+ }
37
+
38
+ #[ tokio:: main]
39
+ async fn main ( ) -> Result < ( ) , Error > {
40
+ tracing_subscriber:: fmt ( )
41
+ . with_max_level ( tracing:: Level :: INFO )
42
+ // disable printing the name of the module in every log line.
43
+ . with_target ( false )
44
+ // disabling time is handy because CloudWatch will add the ingestion time.
45
+ . without_time ( )
46
+ . init ( ) ;
47
+
48
+ run ( service_fn ( function_handler) ) . await
49
+ }
Original file line number Diff line number Diff line change 74
74
"language" : " go"
75
75
}
76
76
]
77
+ },
78
+ {
79
+ "id" : " Rust" ,
80
+ "title" : " Usage Example with Rust:" ,
81
+ "description" : " Consuming Kinesis event with Lambda using Rust without batch item handling." ,
82
+ "snippets" : [
83
+ {
84
+ "snippetPath" : " main.rs" ,
85
+ "language" : " rust"
86
+ }
87
+ ]
77
88
}
78
89
]
79
90
}
You can’t perform that action at this time.
0 commit comments