-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (37 loc) · 1.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"use strict";
class Logless {
constructor(serverless, options) {
this.configLogRetention = () => {
if (this.do) {
this.serverless.cli.log(`Configurating CloudWatch log retention`);
let Resources = this.serverless.service.provider.compiledCloudFormationTemplate.Resources;
this.serverless.service.getAllFunctions().forEach((name) => {
let logGroup = `${name}LogGroup`;
if (Resources[logGroup]) {
this.serverless.cli.log(`Configurating ${logGroup} RetentionInDays: ${this.config.logRetention}`);
Resources[logGroup].Properties.RetentionInDays = this.config.logRetention;
}
});
}
};
this.serverless = serverless;
this.options = options;
this.provider = 'aws';
this.hooks = {
'after:package:compileFunctions': this.configLogRetention,
};
}
get do() {
return this.serverless.service.custom && this.serverless.service.custom.logless && this.serverless.service.custom.logless.logRetention;
}
get config() {
if (this.do) {
return this.serverless.service.custom.logless;
}
else {
this.serverless.cli.log(`No configuration found for Logless`);
return {};
}
}
}
module.exports = Logless;