Search code examples
node.jsreactjsamazon-web-servicesamazon-ec2amazon-cloudwatch

Logging from react to aws cloudwatch


I have a react and node application hosted on aws ec2. I have cloudwatch running as well and it gets all the logs from the node app. I'm trying to also get the logs from the react application to show in cloudwatch.

Upon researching, I discovered 2 posibilities.

  1. Create a route in the node app that will spit out a log whatever it receives in its body
  2. Use the aws cloudwatch library.

I believe the 2nd option is the better more aws way to go about it. I'm just having trouble implementing it... I looked all over the internet but can't find any tutorials or clear documentation and don't know where to start.


Solution

  • We're not supposed to be dumping browser-side error logs directly from the browser to CloudWatch. This presents an issue because posting logs to CloudWatch using SDK outside the AWS ecosystem requires API secret key and secret IDs, which means that it could be exposed to bad elements that could run MITM attacks and intercept our AWS credentials.

    You will have two options to proceed with what you desire to do with less risk:

    • Use client-side libraries (Sentry) that were specifically designed to log errors and debugging information.
    • You can implement the sending of logs via an API that then forwards/proxies the logs towards CloudWatch.