Skip to content

Commit

Permalink
add in log streaming fixes for aws-sdk-v3 (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-yong committed Nov 8, 2023
1 parent 0a82fe0 commit c4f0d5c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"private": true,
"dependencies": {
"babel-polyfill": "^6.7.4",
"lodash": "^4.17.14"
"lodash": "^4.17.14",
"zlib": "^1.0.5"
},
"optionalDependencies": {
"@aws-sdk/client-auto-scaling": "^3.410.0",
Expand Down
32 changes: 17 additions & 15 deletions src/aws_cloud_trail_log_listener.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import zlib from 'zlib.js';
import { S3 } from "@aws-sdk/client-s3";
import each from 'lodash/each.js';
import constants from './cloud_trail_event_config.js';
import AutotagFactory from './autotag_factory.js';
import SETTINGS from './autotag_settings.js';
import zlib from 'zlib';
import { GetObjectCommand, S3 } from '@aws-sdk/client-s3';
import each from 'lodash/each';
import constants from './cloud_trail_event_config';
import AutotagFactory from './autotag_factory';
import SETTINGS from './autotag_settings';

class AwsCloudTrailLogListener {
constructor(cloudtrailEvent, applicationContext, enabledServices) {
Expand Down Expand Up @@ -94,16 +94,18 @@ class AwsCloudTrailLogListener {
return rawContent;
}

retrieveFromS3(logFile) {
return new Promise((resolve, reject) => {
this.s3.getObject(logFile, (err, res) => {
if (err) {
reject(err);
} else {
resolve(res.Body);
}
});
async retrieveFromS3(logFile) {
const getObjectCommand = new GetObjectCommand(logFile);
const { Body } = await this.s3.send(getObjectCommand);

const streamToString = new Promise((resolve, reject) => {
const chunks = [];
Body.on('error', reject);
Body.on('data', chunk => chunks.push(chunk));
Body.on('end', () => resolve(Buffer.concat(chunks)));
});

return streamToString;
}

unGzipContent(zippedContent) {
Expand Down

0 comments on commit c4f0d5c

Please sign in to comment.