Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read cloudwatch logs using `aws-sdk`in nodejs

How can I read cloudwatch logs using aws-sdkin nodejs?

I don't know how to init my config, where can I find any keys/endpoints to my cloudwatch ?

Can someone provide me some example?

import AWS from 'aws-sdk'; 
const cwInstance = new AWS.CloudWatchLogs({
  .....?
})
like image 525
sayicej101 Avatar asked Nov 25 '25 09:11

sayicej101


1 Answers

import AWS from 'aws-sdk'; 

const cloudwatchlogs = new AWS.CloudWatchLogs({apiVersion: '2014-03-28'});
const params = {
  logGroupName: 'STRING_VALUE', /* required */
  logStreamName: 'STRING_VALUE', /* required */
  endTime: 'NUMBER_VALUE',
  limit: 'NUMBER_VALUE',
  nextToken: 'STRING_VALUE',
  startFromHead: true || false,
  startTime: 'NUMBER_VALUE'
};
cloudwatchlogs.getLogEvents(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

For the more information check AWS documentation

like image 155
CyberEternal Avatar answered Nov 27 '25 23:11

CyberEternal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!