Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Run the following commands to connect to the EC2 instance. First, you need to install CloudWatch Agent from S3. Use the below command to download it for AMD64 Ubuntu.

Code Block
$ wget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb

Use the following command to install the Agent:

Code Block
$ sudo dpkg -i -E ./amazon-cloudwatch-agent.deb

After installing the CloudWatch Agent, the user needs to be configured before it can be started. It can be configured in two ways: by manually creating a config file or using the wizard (In which the user needs to answer a series of questions). It generates a config file.

Install Manually create config.json

The log agent uses the config file located at the below path:

Code Block
/opt/aws/amazon-cloudwatch-agent/bin/config.json

From the above path, create or edit the config file with the following content:

Code Block
{
     "agent": {
         "run_as_user": "root"
     },
     "logs": {
         "logs_collected": {
             "files": {
                 "collect_list": [
                     {
                         "file_path": "/var/log/apache2/error.log",
                         "log_group_name": "apache-error-log",
                         "log_stream_name": "{instance_id}"
                     }
                 ]
             }
         }
     }
 }