extern crate chrono; extern crate rusoto_core; extern crate rusoto_logs; use chrono::Utc; use rusoto_core::Region; use rusoto_logs::{ CloudWatchLogs, CloudWatchLogsClient, DescribeLogStreamsRequest, InputLogEvent, PutLogEventsRequest, }; use std::default::Default; fn main() { const LOG_GROUP_NAME: &'static str = "testing"; const LOG_STREAM_NAME: &'static str = "testing"; let client = CloudWatchLogsClient::new(Region::UsEast1); let input_log_event = InputLogEvent { message: "Test log message".to_string(), timestamp: Utc::now().timestamp_millis(), // milliseconds epoch }; // We need the log stream to get the sequence token let mut desc_streams_req: DescribeLogStreamsRequest = Default::default(); desc_streams_req.log_group_name = LOG_GROUP_NAME.to_string(); let streams_resp = client.describe_log_streams(desc_streams_req).sync(); let log_streams = streams_resp.unwrap().log_streams.unwrap(); let stream = &log_streams .iter() .find(|s| s.log_stream_name == Some(LOG_STREAM_NAME.to_string())) .unwrap(); let sequence_token = stream.upload_sequence_token.clone(); let put_log_events_request = PutLogEventsRequest { log_events: vec![input_log_event], // > 1 must sort by timestamp ASC log_group_name: LOG_GROUP_NAME.to_string(), log_stream_name: LOG_STREAM_NAME.to_string(), sequence_token: sequence_token, }; let resp = client.put_log_events(put_log_events_request).sync(); println!("{:#?}", resp); }