Serverless plugin for forwarding CloudWatch logs to a Kinesis Stream
This plugin only works for Serverless deployments to AWS
Make sure you have the following installed before starting:
You will need a Kinesis Stream ARN, and the ARN to a role with a policy like:
CloudWatchLogsRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- logs.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: root
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- kinesis:PutRecords
- kinesis:PutRecord
Resource:
Fn::GetAtt:
- KinesisStream
- Arn
RoleName: kinesis-forwarder-cloudwatchrole
Note the above is just an example cloudformation resource, and you will need to create one appropriate for your use case.
To install the plugin, run:
npm install serverless-log-forwarding-kinesis
Then make the following edits to your serverless.yaml
file:
plugins:
- serverless-log-forwarding-kinesis
custom:
logForwardingKinesis:
destinationARN: '[ARN of Kinesis stream to forward logs to]'
roleARN: '[ARN of the role to use when forwading logs]'
# optional:
filterPattern: '[filter pattern for logs that are sent to Kinesis]'
normalizedFilterID: true # whether to use normalized function name as filter ID
stages:
- '[name of the stage to apply log forwarding]'
- '[another stage name to filter]'
functions:
myFunction:
handler: src/someHandler
# optional properties for per-function configuration:
logForwarding:
# set enabled to false to disable log forwarding for a single given function
enabled: false
To run the test:
npm test
All tests should pass.
If there is an error update the node_module inside the serverless-log-forwarding-kinesis folder:
npm install
The plugin will be packaged with the lambda when deployed as normal using Serverless:
serverless deploy
If you have any security issue to report, contact project maintainers privately.
We welcome pull requests! For your pull request to be accepted smoothly, we suggest that you:
- For any sizable change, first open a GitHub issue to discuss your idea.
- Create a pull request. Explain why you want to make the change and what it’s for. We’ll try to answer any PRs promptly.