I am using winston to generate logs from my express app which is not on cloud. Can I send them to cloudwatch or does cloudwatch only works if your app is running on an EC2 instance?
It will work irrespective of where the app is running. If the app is writing to a file, use the unified cloudwatch agent to send the logs to cloudwatch.
Put it in a container and then use the Docker log driver setting to send to CloudWatch logs. Super simple and you can use Instance Roles instead of having to use IAM keys. Requires no code changes on your part. (Unless your app cant run in a container)
You can also use the CloudWatch Agent to ship logs from non-EC2 servers
The unified CloudWatch agent enables you to do the following: … Collect logs from Amazon EC2 instances and on-premises servers, running either Linux or Windows Server.
You can, but the real question is why would you want to? There are plenty of much more efficient and less expensive log aggregation solutions out there with free tiers. CloudWatch Logs isn’t that good.
We use winstonjs also. It does correctly log to cloud-watch from anywhere, as long as you have setup the AWS cli profile correctly on the machine you’re logging from.
We wanted a SaaS solution because logs are for production app so on-premise would not be a good idea. Splunk was also an alternative but I think its highly paid as compared to cloudwatch and elasticsearch combined.
Btw original python powered cloudwatch log forwarder sucks. I had a lot of headache with it. Recently they made libs for fluentbit and it works like a charm. Bonus is very low resources consumption. https://github.com/aws/aws-for-fluent-bit
All our environments - production, staging, dev - for now. Our environment is very small though for the moment - couple dozen AWS instances across two regions. A lot of issues creep in through logged messages vs basic infrastructure problems like running out of disk space, excess CPU/memory utilization, general capacity issues, etc. so logging is quite important. Graylog server sizing is t2.xlarge and I gave it about 200GB of disk. No additional Elasticsearch cluster nodes. As we scale of course I expect that will grow.
CloudWatch logs will be a fraction of that price with much cheaper and longer retention options. We priced out a bunch of different SaaS options and CloudWatch pricing was almost free in comparison.