Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit c4f0d5c

Browse files
add in log streaming fixes for aws-sdk-v3 (#119)
1 parent 0a82fe0 commit c4f0d5c

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"private": true,
77
"dependencies": {
88
"babel-polyfill": "^6.7.4",
9-
"lodash": "^4.17.14"
9+
"lodash": "^4.17.14",
10+
"zlib": "^1.0.5"
1011
},
1112
"optionalDependencies": {
1213
"@aws-sdk/client-auto-scaling": "^3.410.0",

src/aws_cloud_trail_log_listener.js

+17-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import zlib from 'zlib.js';
2-
import { S3 } from "@aws-sdk/client-s3";
3-
import each from 'lodash/each.js';
4-
import constants from './cloud_trail_event_config.js';
5-
import AutotagFactory from './autotag_factory.js';
6-
import SETTINGS from './autotag_settings.js';
1+
import zlib from 'zlib';
2+
import { GetObjectCommand, S3 } from '@aws-sdk/client-s3';
3+
import each from 'lodash/each';
4+
import constants from './cloud_trail_event_config';
5+
import AutotagFactory from './autotag_factory';
6+
import SETTINGS from './autotag_settings';
77

88
class AwsCloudTrailLogListener {
99
constructor(cloudtrailEvent, applicationContext, enabledServices) {
@@ -94,16 +94,18 @@ class AwsCloudTrailLogListener {
9494
return rawContent;
9595
}
9696

97-
retrieveFromS3(logFile) {
98-
return new Promise((resolve, reject) => {
99-
this.s3.getObject(logFile, (err, res) => {
100-
if (err) {
101-
reject(err);
102-
} else {
103-
resolve(res.Body);
104-
}
105-
});
97+
async retrieveFromS3(logFile) {
98+
const getObjectCommand = new GetObjectCommand(logFile);
99+
const { Body } = await this.s3.send(getObjectCommand);
100+
101+
const streamToString = new Promise((resolve, reject) => {
102+
const chunks = [];
103+
Body.on('error', reject);
104+
Body.on('data', chunk => chunks.push(chunk));
105+
Body.on('end', () => resolve(Buffer.concat(chunks)));
106106
});
107+
108+
return streamToString;
107109
}
108110

109111
unGzipContent(zippedContent) {

0 commit comments

Comments
 (0)