An Amazon SNS transport for winston 3.x specialized for JSON logs in Sumo Logic.
Sumo Logic is not required to use this package if you only want to send nicely formatted JSON messages to Amazon SNS.
Requires Node.js 10.13.x or greater.
const {createLogger} = require('winston');
const AWS = require('aws-sdk');
const WinstonSnsSumoLogic = require('winston-sns-sumo-logic');
const logger = createLogger();
const sns = new AWS.SNS({
region: '..',
accessKeyId: '..',
secretAccessKey: '..'
});
logger.add(new WinstonSnsSumoLogic({
level: 'error',
sns,
topicArn: '..'
}));
level
: Level of messages that should be logged. Defaults toinfo
.sns
(required): The AWS.SNS instance to log to.topicArn
(required): The Amazon SNS topic ARN where the messages to be sent.body
: The base JSON message body. Should not containtimestamp
,level
,message
, ormeta
. Forbidden fields will be overwritten.
Let's say options.body
was configured to be
{
model: 'Falcon 9',
flight: 20
}
When the the following message is logged
const landingDetails = {
location: {
latitude: 28.4859,
longitude: -80.5444
},
fuel: 'nominal'
}
winston.info('successful landing', landingDetails);
Then the resulting Amazon SNS message body would be
{
"model": "Falcon 9",
"flight": 20,
"timestamp": 1450748385666,
"level": "info",
"message": "successful landing",
"meta": {
"location": {
"latitude": 28.4859,
"longitude": -80.5444
},
"fuel": "nominal"
}
}
Where timestamp
is the Unix Epoch in milliseconds when the message was logged.
There is another winston-sns transport, but it does not work well with Sumo Logic. That transport is focused on sending text based messaged to Amazon SNS, where as this transport focuses on sending JSON based messages with Sumo Logic compatible timestamps.
$ npm install winston-sns-sumo-logic --save
- Create a Sumo Logic HTTP Collector
- Create a Amazon SNS topic
- Add Sumo Logic HTTP Collector endpoint as an HTTPS subscriber to the new topic
- Subscribe to SNS Notifications
- Enable Raw Message Delivery
- Add winston-sns-sumo-logic as a new transport
- Configure with topic ARN
- Ensure AWS Access Key has permission to publish messages to Amazon SNS