I configured Amazon CloudWatch to export log data to Amazon S3, but the log data is either missing or invalid. How do I resolve this issue?

Last updated: 2022-08-05

I configured Amazon CloudWatch to export log data to Amazon Simple Storage Service (Amazon S3) as described at Exporting log data to Amazon S3 using the AWS Command Line Interface (AWS CLI). But despite completing these steps, I can't locate any useful log file data at the specified Amazon S3 destination. What do I need to do?

Short description

This issue occurs because you must specify the time interval for the log data using timestamps expressed as the number of milliseconds that have elapsed since Jan 1, 1970 00:00:00 UTC.

Resolution

Export CloudWatch log data to Amazon S3 by specifying the time interval for the log data using starting and ending timestamps that are expressed in milliseconds.

For example, to export CloudWatch log data to an Amazon S3 bucket or folder for the previous two-hour period, use the following syntax:

aws logs create-export-task --task-name "example-task" --log-group-name "/var/logs/example-logs" --from $(($(date -d "-2 hours" +%s%N)/1000000)) --to $(($(date +%s%N)/1000000)) --destination " log_bucket" --destination-prefix "example-logs"