In this hands-on lab, we will create and configure a CloudTrail trail and a CloudWatch Logs log stream in order to set up monitoring and access alerts for an S3 bucket. Specifically, we’ll create the trail for monitoring access to the S3 bucket, the CloudWatch Logs log stream to allow searching and filtering of the logs, and then a CloudWatch metric filter and alarm on that metric filter to generate an alert whenever there is any access to an S3 bucket.
This will demonstrate how to build effective monitoring and alerting with specific AWS API calls.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Create a CloudTrail Trail
Create a CloudTrail trail in the AWS Console:
- Create an S3 bucket to monitor with CloudTrail.
- Create a CloudTrail trail in the CloudTrail Management Console.
- Turn off management events.
- Set up logging for the data events happening to the S3 bucket you created.
- Upload some data to the S3 bucket.
- Create and Configure a CloudWatch Log Group and CloudWatch Alarm with Your CloudTrail Trail
After creating your CloudTrail trail, create a CloudWatch log group:
- Go to the CloudTrail Management Console.
- Select the CloudTrail trail you already created.
- Add a CloudWatch log group under the CloudWatch section.
- Test the CloudWatch log group by uploading and downloading files in the S3 bucket you created.
- Confirm that you see data coming in for the CloudWatch log group.
- Create a custom metric filter for the CloudWatch log group you created using the code provided for this lab.
- Create a CloudWatch alarm based on this custom metric.
- Verify your email for the CloudWatch alarm.
- Test the alarm by uploading and downloading objects in the S3 bucket that your CloudTrail trail monitors.