An enterprise financial services company runs a payment settlement application on a fleet of Amazon EC2 instances. The application writes transaction events to `/var/log/settlement/transactions.log`. An hourly cron job rotates the log file by renaming the current file to `/var/log/settlement/transactions.log.YYYY-MM-DD-HH` and creating a new empty `/var/log/settlement/transactions.log` file. A solutions architect is configuring the unified Amazon CloudWatch agent on these instances to publish the log data to CloudWatch Logs. Which configuration approach should the solutions architect use to ensure all log entries are collected reliably across rotations without duplicating or missing log events?
- Configure the CloudWatch agent log file path to `/var/log/settlement/transactions.log`. The agent will automatically track the file descriptor or inode to process the rotated file to completion, and then open the newly created active log file.Answer
- BConfigure the CloudWatch agent log file path using a wildcard pattern as `/var/log/settlement/transactions.log*`. This ensures that both the active log file and all rotated files are continuously monitored.
- CConfigure the CloudWatch agent log file path to `/var/log/settlement/transactions.log` and schedule a cron job that restarts the CloudWatch agent service hourly immediately after the log rotation script finishes.
- DConfigure the application to bypass local logging and write directly to an S3 bucket in a central logging account, using a bucket policy that grants `s3:PutObject` access to the `log-delivery.amazonaws.com` service principal without specifying individual AWS account IDs.
Answer
Configure the CloudWatch agent log file path to the active log file `/var/log/settlement/transactions.log`. The agent will automatically track the file descriptor or inode to process the rotated file to completion, and then open the newly created active log file.
The correct configuration is to point the CloudWatch agent to the active log file path. The CloudWatch agent keeps an open file handle (tracking the inode) of the file it is reading. When the log rotation system renames the file, the agent continues reading from the renamed file via its open file handle until it reaches the end of the file (EOF). Concurrently, the agent detects that a new file has been created at the configured path and opens it to begin reading new log entries. This built-in behavior ensures seamless log collection without duplication or missing events.
Step-by-Step Solution
Key Concept
The unified Amazon CloudWatch agent tracks active log files by their file descriptors/inodes, allowing it to handle standard log rotation automatically without needing wildcards or service restarts.