Skip to content

Commit

Permalink
Merge pull request #5562 from exoego/log-retenion-regression
Browse files Browse the repository at this point in the history
Fix logRetentionInDays regression in AWS
  • Loading branch information
dschep committed Dec 5, 2018
2 parents 510a01f + f129894 commit 00756dd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
11 changes: 6 additions & 5 deletions lib/plugins/aws/package/lib/mergeIamTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ module.exports = {
};

if (_.has(this.serverless.service.provider, 'logRetentionInDays')) {
if (_.isInteger(this.serverless.service.provider.logRetentionInDays) &&
this.serverless.service.provider.logRetentionInDays > 0) {
newLogGroup[logGroupLogicalId].Properties.RetentionInDays
= this.serverless.service.provider.logRetentionInDays;
const rawRetentionInDays = this.serverless.service.provider.logRetentionInDays;
const retentionInDays = parseInt(rawRetentionInDays, 10);
if (_.isInteger(retentionInDays) && retentionInDays > 0) {
newLogGroup[logGroupLogicalId].Properties.RetentionInDays = retentionInDays;
} else {
const errorMessage = 'logRetentionInDays should be an integer over 0';
const errorMessage =
`logRetentionInDays should be an integer over 0 but ${rawRetentionInDays}`;
throw new this.serverless.classes.Error(errorMessage);
}
}
Expand Down
28 changes: 15 additions & 13 deletions lib/plugins/aws/package/lib/mergeIamTemplates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,20 +296,22 @@ describe('#mergeIamTemplates()', () => {

it('should add RetentionInDays to a CloudWatch LogGroup resource if logRetentionInDays is given'
, () => {
awsPackage.serverless.service.provider.logRetentionInDays = 5;
const normalizedName = awsPackage.provider.naming.getLogGroupLogicalId(functionName);
return awsPackage.mergeIamTemplates().then(() => {
expect(awsPackage.serverless.service.provider.compiledCloudFormationTemplate
.Resources[normalizedName]
).to.deep.equal(
{
Type: 'AWS::Logs::LogGroup',
Properties: {
LogGroupName: awsPackage.provider.naming.getLogGroupName(functionName),
RetentionInDays: 5,
},
}
[5, '5'].forEach((logRetentionInDays) => {
awsPackage.serverless.service.provider.logRetentionInDays = logRetentionInDays;
const normalizedName = awsPackage.provider.naming.getLogGroupLogicalId(functionName);
return awsPackage.mergeIamTemplates().then(() => {
expect(awsPackage.serverless.service.provider.compiledCloudFormationTemplate
.Resources[normalizedName]
).to.deep.equal(
{
Type: 'AWS::Logs::LogGroup',
Properties: {
LogGroupName: awsPackage.provider.naming.getLogGroupName(functionName),
RetentionInDays: 5,
},
}
);
});
});
});

Expand Down

0 comments on commit 00756dd

Please sign in to comment.