This project uses the Serverless Framework to deploy an AWS Lambda function which subscribes to Amazon CloudWatch log groups, consumes their log events, and continuously pushes them into a Rollbar project.
You will need to add two configuration files to run this project: a dotenv, and a YAML file.
First, create a dotenv environment file such as .env.{stage}
(e.g. .env.live
) in the project directory.
Use the following configuration as a template to get you started, adding your own values where appropriate:
STAGE=live
LOG_LEVEL=DEBUG
ROLLBAR_ACCESS_TOKEN={POST_SERVER_ITEM_ACCESS_TOKEN}
ROLLBAR_ENVIRONMENT=production
ROLLBAR_LANGUAGE=Java
ROLLBAR_FILTER_THRESHOLD=WARNING
The ROLLBAR_FILTER_THRESHOLD
variable will set a threshold to limit the number of log messages sent to Rollbar.
The threshold will send higher priority messages and is inclusive of the value. e.g. WARNING
will send WARNING
and ERROR logs. INFO
will send INFO, WARNING, and ERROR logs.
You will then need to add a .env-config.yml
file, to specify the CloudWatch log subscriptions to subscribe our AWS
Lambda to, in the project's serverless.yml
file.
cloudwatchLogs:
- cloudwatchLog: /aws/lambda/my-project-${self:provider.stage}-execute
$ serverless deploy -v --env=live
Amazon CloudWatch logs are provided to AWS Lambda as strings, and so we need to parse the message to determine the
logging level, to better inform Rollbar. We analyse the first 200
characters of the log message, and look for
standalone keywords, such as CRITICAL
, SEVERE
, FATAL
, and WARN
etc. It's typical your log messages would have
these log level keywords. If we are unable to determine the log level, we default to INFO
.