Question

Difficulty: MediumImproving Operational Excellence via Monitoring and Logging

An enterprise operates a multi-account AWS environment managed under AWS Organizations. In the production account, a critical payment processing application runs on a fleet of Amazon EC2 instances. The application writes its logs to a local directory at /var/log/payment/app.log. To manage local disk space, the application's logging framework rotates the logs hourly by renaming the active file to app-YYYY-MM-DD-HH.log (e.g., app-2026-07-16-10.log) and creating a new empty app.log file. The CloudWatch unified agent is deployed on the EC2 instances, configured to stream /var/log/payment/app.log to a centralized CloudWatch Logs account. The security operations team reports that after the hourly rotation, the centralized log group stops receiving new log entries, and streaming only resumes after manually restarting the CloudWatch agent service on each instance. Which of the following configuration modifications is the most operationally efficient way to resolve this issue and ensure continuous log streaming?

  1. A
    Maintain the static file_path parameter as /var/log/payment/app.log and schedule a cron job on the EC2 instances to restart the CloudWatch agent service every hour immediately following the log rotation.
  2. Update the CloudWatch agent configuration file on the EC2 instances by changing the file_path parameter to /var/log/payment/app-*.log to enable the agent to dynamically track and stream newly created log files matching the wildcard pattern.Answer
  3. C
    Configure an Amazon Kinesis Data Firehose delivery stream to write the logs directly to a centralized Amazon S3 bucket, and apply an S3 bucket policy in the destination account that grants write permissions using only the aws:SourceOrgID condition key without specifying the Kinesis Firehose service principal.
  4. D
    Enable KMS encryption on the target CloudWatch log group in the central logging account using the default AWS-managed KMS key (aws/logs) and modify the key policy to delegate cross-account write permissions to the production account.

Answer

Update the CloudWatch agent configuration file on the EC2 instances by changing the file_path parameter to /var/log/payment/app-*.log to enable the agent to dynamically track and stream newly created log files matching the wildcard pattern.
Updating the CloudWatch agent configuration to use a wildcard pattern (/var/log/payment/app-*.log) is the most operationally efficient solution. When the file_path contains a wildcard, the CloudWatch agent dynamically monitors the directory for new files matching the pattern. When log rotation renames the active file and creates a new file, the agent continues tracking the files natively without requiring any service restarts.

Step-by-Step Solution

1
Analyze the log rotation mechanism and current agent configuration.
The application writes to a static file but rotates logs by renaming them to timestamped files, while the agent configuration is restricted to a static path (/var/log/payment/app.log).
This configuration mismatch causes the agent to lose track of the log stream after rotation because the file descriptor changes and new content is written to a renamed file.
2
Identify the native CloudWatch agent solution for dynamic log files.
Using a wildcard pattern (/var/log/payment/app-*.log) enables the CloudWatch agent to dynamically monitor the directory and automatically pick up newly created log files.
This removes the need for manual restarts or operational scripts, aligning with AWS operational excellence best practices.
3
Evaluate and eliminate incorrect or sub-optimal distractors.
Restarting the agent hourly via cron is operationally inefficient. Modifying cross-account bucket policies without the proper principal, or using AWS-managed KMS keys for cross-account access, are invalid AWS configurations that do not address the core issue.
AWS-managed KMS keys do not support policy edits, and S3 bucket policies for cross-account access require a designated principal.

Key Concept

Dynamic log file tracking using wildcards in the unified CloudWatch agent configuration.
Rate this question