Skip to content

Commit

Permalink
aws sdk v3
Browse files Browse the repository at this point in the history
  • Loading branch information
zendagin committed Sep 13, 2021
1 parent 19274fe commit a394491
Show file tree
Hide file tree
Showing 7 changed files with 1,536 additions and 294 deletions.
23 changes: 11 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

var util = require('util'),
winston = require('winston'),
AWS = require('aws-sdk'),
cloudWatchIntegration = require('./lib/cloudwatch-integration'),
{CloudWatchLogs} = require('@aws-sdk/client-cloudwatch-logs'),
isEmpty = require('lodash.isempty'),
assign = require('lodash.assign'),
isError = require('lodash.iserror'),
Expand Down Expand Up @@ -35,14 +35,6 @@ var WinstonCloudWatch = function(options) {
if (options.cloudWatchLogs) {
this.cloudwatchlogs = options.cloudWatchLogs;
} else {
if (this.proxyServer) {
AWS.config.update({
httpOptions: {
agent: require('proxy-agent')(this.proxyServer)
}
});
}

var config = {};

if (awsAccessKeyId && awsSecretKey && awsRegion) {
Expand All @@ -54,11 +46,18 @@ var WinstonCloudWatch = function(options) {
config = { region: awsRegion };
}

if (this.proxyServer) {
config.requestHandler = new (require('@aws-sdk/node-http-handler').NodeHttpHandler)({
httpAgent: require('proxy-agent')(this.proxyServer),
httpsAgent: require('proxy-agent')(this.proxyServer)
})
}

if (options.awsOptions) {
config = assign(config, options.awsOptions);
}

this.cloudwatchlogs = new AWS.CloudWatchLogs(config);
this.cloudwatchlogs = new CloudWatchLogs(config);
}

debug('constructor finished');
Expand All @@ -69,7 +68,7 @@ util.inherits(WinstonCloudWatch, winston.Transport);
WinstonCloudWatch.prototype.log = function (info, callback) {
debug('log (called by winston)', info);

if (!isEmpty(info.message) || isError(info.message)) {
if (!isEmpty(info.message) || isError(info.message)) {
this.add(info);
}

Expand Down Expand Up @@ -134,7 +133,7 @@ WinstonCloudWatch.prototype.submit = function(callback) {
);
};

WinstonCloudWatch.prototype.kthxbye = function(callback) {
WinstonCloudWatch.prototype.kthxbye = function(callback) {
debug('clearing interval');
clearInterval(this.intervalId);
this.intervalId = null;
Expand Down
10 changes: 5 additions & 5 deletions lib/cloudwatch-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ lib.upload = function(aws, groupName, streamName, logEvents, retentionInDays, op
// InvalidSequenceToken means we need to do a describe to get another token
// also do the same if ResourceNotFound as that will result in the last token
// for the group being set to null
if (err.code === 'InvalidSequenceTokenException' || err.code === 'ResourceNotFoundException') {
debug(err.code + ', retrying', true);
if (err.name === 'InvalidSequenceTokenException' || err.name === 'ResourceNotFoundException') {
debug(err.name + ', retrying', true);
lib.submitWithAnotherToken(aws, groupName, streamName, payload, retentionInDays, options, cb)
} else {
debug('error during putLogEvents', err, true)
Expand Down Expand Up @@ -162,7 +162,7 @@ lib.ensureGroupPresent = function ensureGroupPresent(aws, name, retentionInDays,
var params = { logGroupName: name };
aws.describeLogStreams(params, function(err, data) {
// TODO we should cb(err, false) if there's an error?
if (err && err.code == 'ResourceNotFoundException') {
if (err && err.name == 'ResourceNotFoundException') {
debug('create group');
return aws.createLogGroup(params, lib.ignoreInProgress(function(err) {
if(!err) lib.putRetentionPolicy(aws, name, retentionInDays);
Expand Down Expand Up @@ -219,8 +219,8 @@ lib.getStream = function getStream(aws, groupName, streamName, cb) {

lib.ignoreInProgress = function ignoreInProgress(cb) {
return function(err, data) {
if (err && (err.code == 'OperationAbortedException' ||
err.code == 'ResourceAlreadyExistsException')) {
if (err && (err.name == 'OperationAbortedException' ||
err.name == 'ResourceAlreadyExistsException')) {
debug('ignore operation in progress', err.message);
cb(null, data);
} else {
Expand Down
Loading

0 comments on commit a394491

Please sign in to comment.