Skip to content
Home » AWS – Cloudwatch Logs

AWS – Cloudwatch Logs

aws cloudwatch

Set up AWS cloud watch Logs:

  1. Configure your IAM role or user for Cloud Watch Logs:
    Cloud Watch uses the Identity and Access Management (IAM) service for authentication and authorization so follow step:1 in below AWS doc link.
  2. Download AWS cloud watch logs agent setup file:

  3. Run AWS cloud watch agent setup file for configuration:

    sudo python ./ --region us-west-2

    It will ask for AWS access key and secret key to continue the setup so provide that information when prompted. Then it will ask for log detail for the file path and other configuration for logging file to aws cloud watch.
    below is the sample parameters where app-application-logs will be the group name in aws cloud watch and will be the file path on the server from where all logs will go to cloud watch.

    datetime_format = %Y-%m-%d %H:%M:%S
    file = /var/www/html/application/logs/*.*
    buffer_duration = 5000
    log_stream_name = {instance_id}
    initial_position = start_of_file
    log_group_name = app-application-logs
  4. Setup and configuration will be done once above process get completed and AWS cloud watch agent will continue writing specified log files to AWS cloud watch.

    Note: Configuration file path: 

    You can begin accessing new log events after a few moments at

Controlling aws cloud watch:

  1. Control aws cloud watch daemon.
    sudo service awslogs stop         #To stop aws log.
    sudo service awslogs start        #To start aws log.
    sudo service awslogs restart    #To restart awslog.
  2. To see diagnostic information for the CloudWatch Logs Agent, see:

  3. You can rerun interactive setup using:
    sudo python ./ --region us-west-2 --only-generate-config
  4. You can also set the expiration dates
    sudo python ./ --region us-west-2 --only-generate-config

    for the log for aws cloudwatch Log group. so suppose if expiration is set to 5 days then logs older than 5 days will be deleted from cloudwatch Logs.Screen Shot 2016-07-15 at 6.57.08 pmScreen Shot 2016-07-15 at 6.57.34 pmScreen Shot 2016-07-15 at 6.57.48 pm

Uninstall aws cloud watch agent and configurations:

  1. Run below commands to remove related files and uninstall cloud watch setup and agent:

    #Stop the awslogs service.
    service awslogs stop
    #Remove cloud watch related files.
    rm -rf /var/awslogs
    rm -rf /etc/init.d/awslogs
    rm -rf /home/ubuntu/
  2. Its done. Restart the server if required.


  1. If any issues comes like Trying to install CloudWatch Agent “Failed to create virtualenv” during setup installation then run below command:
    export LC_ALL=C
    (It forces applications to use the default language for output, and forces sorting to be bytewise)



Leave a Reply

Your email address will not be published. Required fields are marked *