Skip to content

EC2 Instance Cloudwatch logs configuration

0

Hello to everyone guys. I have an instance with Ubuntu 24 version. I have already created the role, added the policy CloudWatchAgentServerPolicy. Configured the agent policy from EC2 console but in the log group doesn't appear anything. Maybe i didn't use the correct procedure?

Sorry for my basic english

asked 2 years ago817 views

1 Answer
1
Accepted Answer

It sounds like you've taken some good initial steps to set up CloudWatch logging for your EC2 instance, but there may be a few additional steps needed to get the logs appearing in CloudWatch. Here's what you can do to troubleshoot and ensure proper configuration:

  1. Install the CloudWatch agent: For Ubuntu, you need to download and install the CloudWatch agent package. You can do this by running these commands:

    For x86-64 architecture: wget https://amazoncloudwatch-agent.s3.amazonaws.com/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb sudo dpkg -i -E ./amazon-cloudwatch-agent.deb

    For ARM64 architecture: wget https://amazoncloudwatch-agent.s3.amazonaws.com/ubuntu/arm64/latest/amazon-cloudwatch-agent.deb sudo dpkg -i -E ./amazon-cloudwatch-agent.deb

  2. Configure the CloudWatch agent: After installation, you need to create a configuration file that specifies which logs to collect. You can do this manually or use the configuration wizard:

    sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard

  3. Start the CloudWatch agent: Once configured, start the agent with this command:

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

  4. Check agent status: Verify the agent is running correctly:

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

  5. Verify log groups: Check if the log groups are created in the CloudWatch console. The log group names should match what you specified in your configuration.

  6. Check instance permissions: Ensure your EC2 instance role has the necessary permissions to send logs to CloudWatch.

If you've followed these steps and still don't see logs, check the agent's own logs for any errors:

/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log

Remember, it may take a few minutes for logs to appear in CloudWatch after configuration. If issues persist, double-check your configuration file and ensure the specified log files exist on your instance.
Sources
How to setup cloudwatch agent on EC2 instance running with ubuntu | AWS re:Post
How to update clodwatch agent config on a Ec2 | AWS re:Post

answered 2 years ago

EXPERT

reviewed 2 years ago

  • Thanks for the answer, howerer how can I find the file configuration in the instance if I used the online console wizard?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.