Skip to content

Instantly share code, notes, and snippets.

@DoZator
Last active December 13, 2022 07:34
Show Gist options
  • Save DoZator/1364c0e730dbd312ee465c9d58d0c175 to your computer and use it in GitHub Desktop.
Save DoZator/1364c0e730dbd312ee465c9d58d0c175 to your computer and use it in GitHub Desktop.
Install CloudWatch agent on Ubuntu (setup AWS IAM role for EC2)

Download the Cloudwatch agent

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

Install Cloudwatch agent package

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

Start the Cloudwatch agent with custom config

$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/path_to_config/config.json -s

Check the agent status

$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a status

Check agent service sate

$ sudo service amazon-cloudwatch-agent status

Add AWS IAM role for CloudWatch access

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents",
                "logs:DescribeLogStreams"
            ],
            "Resource": [
                "arn:aws:logs:*:*:*"
            ]
        }
    ]
}

Then assign role to EC2 instance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment