-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable unit tests that rely on `aws-sdk` + `aws-sdk-mock`
- Loading branch information
Showing
9 changed files
with
199 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,33 @@ | ||
let aws = require('aws-sdk') | ||
|
||
module.exports = function deleteLogs ({ StackName, update }, callback) { | ||
let cloudwatch = new aws.CloudWatchLogs() | ||
let logGroups = [] | ||
function getLogs (nextToken, cb) { | ||
let params = { | ||
logGroupNamePrefix: `/aws/lambda/${StackName}-` | ||
} | ||
if (nextToken) params.nextToken = nextToken | ||
cloudwatch.describeLogGroups(params, function (err, data) { | ||
if (err) cb(err) | ||
else { | ||
data.logGroups.forEach(l => { | ||
logGroups.push(l.logGroupName) | ||
}) | ||
if (data.nextToken) getLogs(data.nextToken, cb) | ||
else cb() | ||
module.exports = function deleteLogs ({ aws, StackName, update }, callback) { | ||
aws.cloudwatchlogs.DescribeLogGroups({ | ||
logGroupNamePrefix: `/aws/lambda/${StackName}-`, | ||
paginate: true, | ||
}) | ||
.then(data => { | ||
if (data?.logGroups?.length) { | ||
let logGroups = data.logGroups.map(({ logGroupName }) => logGroupName) | ||
deleter(aws, logGroups, update, callback) | ||
} | ||
else callback() | ||
}) | ||
} | ||
getLogs(null, function (err) { | ||
if (err) callback(err) | ||
else if (logGroups.length) { | ||
let timer = 0 | ||
let numComplete = 0 | ||
logGroups.forEach(log => { | ||
timer += 400 // max of about 2-3 transactions per second :/ | ||
let params = { logGroupName: log } | ||
setTimeout(function delayedDelete () { | ||
cloudwatch.deleteLogGroup(params, function (err /* , data */) { | ||
if (err) update.warn(err) | ||
numComplete++ | ||
if (logGroups.length === numComplete) callback() | ||
}) | ||
}, timer) | ||
}) | ||
} | ||
else callback() | ||
.catch(err => callback(err)) | ||
} | ||
|
||
function deleter (aws, logGroups, update, callback) { | ||
let timer = 0 | ||
let numComplete = 0 | ||
logGroups.forEach(log => { | ||
timer += 400 // max of about 2-3 transactions per second :/ | ||
setTimeout(function delayedDelete () { | ||
aws.cloudwatchlogs.DeleteLogGroup({ logGroupName: log }) | ||
.then(() => { | ||
numComplete++ | ||
if (logGroups.length === numComplete) callback() | ||
}) | ||
.catch(err => { | ||
numComplete++ | ||
update.warn(err) | ||
}) | ||
}, timer) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.