serverless-log-forwarding
Advanced tools
Comparing version
@@ -10,4 +10,10 @@ # Changelog | ||
## [1.2.1] - 2019-10-09 | ||
## [1.3.0] - 2018-12-11 | ||
### Added | ||
- Added support for a role arn parameter which allows for AWS Kinesis streams to be added as subscription filters. | ||
## [1.2.1] - 2018-10-09 | ||
### Changed | ||
@@ -14,0 +20,0 @@ |
33
index.js
@@ -57,2 +57,3 @@ 'use strict'; | ||
const normalizedFilterID = !(service.custom.logForwarding.normalizedFilterID === false); | ||
const roleArn = service.custom.logForwarding.roleArn || ''; | ||
// Get options and parameters to make resources object | ||
@@ -64,12 +65,15 @@ const arn = service.custom.logForwarding.destinationARN; | ||
// Only one lambda permission is needed | ||
const resourceObj = { | ||
LogForwardingLambdaPermission: { | ||
Type: 'AWS::Lambda::Permission', | ||
Properties: { | ||
FunctionName: arn, | ||
Action: 'lambda:InvokeFunction', | ||
Principal: principal, | ||
const resourceObj = {}; | ||
if (!roleArn) { | ||
_.extend(resourceObj, { | ||
LogForwardingLambdaPermission: { | ||
Type: 'AWS::Lambda::Permission', | ||
Properties: { | ||
FunctionName: arn, | ||
Action: 'lambda:InvokeFunction', | ||
Principal: principal, | ||
}, | ||
}, | ||
}, | ||
}; | ||
}); | ||
} | ||
/* get list of all functions in this lambda | ||
@@ -88,2 +92,4 @@ and filter by those which explicitly declare logForwarding.enabled = false | ||
normalizedFilterID, | ||
roleArn, | ||
dependsOn: (roleArn === '') ? ['LogForwardingLambdaPermission'] : [], | ||
}); | ||
@@ -121,7 +127,8 @@ /* merge new SubscriptionFilter with current resources object */ | ||
}, | ||
DependsOn: [ | ||
'LogForwardingLambdaPermission', | ||
functionLogGroupId, | ||
], | ||
DependsOn: _.union(options.dependsOn, [functionLogGroupId]), | ||
}; | ||
if (!(options.roleArn === '')) { | ||
filter[filterLogicalId].Properties.RoleArn = options.roleArn; | ||
} | ||
return filter; | ||
@@ -128,0 +135,0 @@ } |
{ | ||
"name": "serverless-log-forwarding", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "a serverless plugin to forward logs to given lambda function", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -43,2 +43,3 @@ # serverless-log-forwarding | ||
# optional: | ||
roleArn: '[ARN of the IAM role that grants Cloudwatch Logs permissions]' | ||
filterPattern: '[filter pattern for logs that are sent to Lambda function]' | ||
@@ -45,0 +46,0 @@ normalizedFilterID: true # whether to use normalized function name as filter ID |
@@ -22,2 +22,7 @@ const chai = require('chai'); | ||
}; | ||
const correctConfigWithRoleArn = { | ||
destinationARN: 'arn:aws:lambda:us-moon-1:314159265358:function:testforward-test-forward', | ||
roleArn: 'arn:aws:lambda:us-moon-1:314159265358:role/test-iam-role', | ||
normalizedFilterID: false, | ||
}; | ||
@@ -378,2 +383,39 @@ const Serverless = require('serverless'); | ||
}); | ||
it('uses the roleArn property if set', () => { | ||
const plugin = constructPluginResources(correctConfigWithRoleArn); | ||
const expectedResources = { | ||
Resources: { | ||
TestExistingFilter: { | ||
Type: 'AWS:Test:Filter', | ||
}, | ||
SubscriptionFiltertestFunctionOne: { | ||
Type: 'AWS::Logs::SubscriptionFilter', | ||
Properties: { | ||
DestinationArn: 'arn:aws:lambda:us-moon-1:314159265358:function:testforward-test-forward', | ||
FilterPattern: '', | ||
LogGroupName: '/aws/lambda/test-service-test-stage-testFunctionOne', | ||
RoleArn: 'arn:aws:lambda:us-moon-1:314159265358:role/test-iam-role', | ||
}, | ||
DependsOn: [ | ||
'TestFunctionOneLogGroup', | ||
], | ||
}, | ||
SubscriptionFiltertestFunctionTwo: { | ||
Type: 'AWS::Logs::SubscriptionFilter', | ||
Properties: { | ||
DestinationArn: 'arn:aws:lambda:us-moon-1:314159265358:function:testforward-test-forward', | ||
FilterPattern: '', | ||
LogGroupName: '/aws/lambda/test-service-test-stage-testFunctionTwo', | ||
RoleArn: 'arn:aws:lambda:us-moon-1:314159265358:role/test-iam-role', | ||
}, | ||
DependsOn: [ | ||
'TestFunctionTwoLogGroup', | ||
], | ||
}, | ||
}, | ||
}; | ||
plugin.updateResources(); | ||
expect(plugin.serverless.service.resources).to.eql(expectedResources); | ||
}); | ||
}); | ||
@@ -380,0 +422,0 @@ |
Sorry, the diff of this file is too big to display
191379
1.16%5325
0.91%95
1.06%