Skip to content

How to send custom JSON application logs to CloudWatch?

0

I'm sorry for perhaps a dumb question, but I simply can't find the right doc to get me going. I have an Ubuntu 24.04 EC2 instance with a custom application that is creating audit logs in a JSON format. The JSON format, for example is like the following below. Can someone provide the minimal steps to get this working??

I have tried what I think is the following:

  1. Installed the aws cli.
  2. aws configure --profile AmazonCloudWatchAgent --> I do not have an IAM but using a Access/Secret key that should have full access at the moment.
  3. Found some article that says to download the CloudWatch agent. I think I have done this and running, but I am not sure if additional configuration is needed. I ran a command line wizard where it asked me several things, and I specified the directly where to get my logs from (btw, there are several .log files being generated).
  4. In CloudWatch, created a LogGroup and stream inside the group.

At this point, nothing is getting captured in CloudWatch and I don't know enough to know what to configured. The AWS documentation is all over the place and very difficult to find the right information.

{"version":"1.1","timestamp":1740063559309,"eventId":"f7407c30-0770-4964-b846-bd3cb7bb54a1","event":"GENERATE_TOKEN","eventLevel":"LEVEL_1","status":"Success","statusCode":"200","actor":"portaladmin","actorId":"935991e073904e308f358731c168b414","actorRole":"account_admin","sourceIp":"134.238.169.246","destinationIp":"172.31.33.45","destinationHost":"ip-172-31-33-45","resource":"/portal/sharing/rest/generateToken","data":{"requestId":"717b933809724405822a983145ec6d11","createTimestamp":"Thu Feb 20 14:59:19 UTC 2025"},"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36","message":" User : portaladmin last login Thu Feb 20 14:58:47 UTC 2025"}

asked 2 years ago801 views

1 Answer
0

Hello.

aws configure --profile AmazonCloudWatchAgent --> I do not have an IAM but using a Access/Secret key that should have full access at the moment.

EC2 does not require setting an access key.
Attach an IAM role to EC2 instead.
I think the following document will be helpful for creating an IAM role.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create-iam-roles-for-cloudwatch-agent.html

Please try running the CloudWatch Agent startup command described in the following document.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-commandline-fleet.html#start-CloudWatch-Agent-EC2-commands-fleet

There is also a log file for the CloudWatch Agent itself, so check there to see if any errors have occurred.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/troubleshooting-CloudWatch-Agent.html

EXPERT

answered 2 years ago

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.