This Rust application demonstrates how to integrate with AWS CloudWatch Logs using the AWS SDK for Rust. It allows you to create a log group, log stream, and send log events to AWS CloudWatch Logs. This is a foundational example that can be useful for logging and monitoring your applications in the AWS environment.
Before running this code, ensure you have the following prerequisites:
- Rust: Make sure you have Rust installed on your system.
- AWS CLI Configuration: You must have the AWS CLI configured with the necessary credentials and default region. Set the following environment variables:
AWS_ACCESS_KEY_ID
: Your AWS Access Key.AWS_SECRET_ACCESS_KEY
: Your AWS Secret Access Key.AWS_DEFAULT_REGION
: Your preferred AWS region.
-
Clone the Repository:
git clone https://github.com/yourusername/aws-cloudwatch-logs-rust.git cd aws-cloudwatch-logs-rust
-
Run the application using Cargo:
cargo run
-
View Logs: To view the logs generated by the application, follow these steps:
-
Open the AWS CloudWatch Logs console in your web browser.
-
In the console, navigate to the log group that was created by the application. You can find it using the name specified in the code, typically "DistiLogs."
-
Within the log group, you'll find a log stream named "ApplicationLogs."
-
Select the log stream to view the log events generated by the Rust application. You should see the sample log event that was sent during the application's execution.
-
That's it! You've successfully run the application and checked the logs in AWS CloudWatch Logs.