Skip to content

kauelima21/serverless-logs-insights

Repository files navigation

Serverless Logs Insights

Plugin for the Serverless Framework that simplifies advanced queries in AWS CloudWatch Logs Insights directly through the CLI, allowing you to filter, analyze, and visualize Lambda function logs in a practical and efficient way.

Installation

Add the plugin to your Serverless project:

npm install --save-dev serverless-logs-insights

Configuration

In your serverless.yml file, add the plugin and configure custom queries under custom.logsInsights.queries:

plugins:
  - serverless-logs-insights

custom:
  logsInsights:
    queries:
      errors: "fields @timestamp, @message | filter @message like /error/ | sort @timestamp desc | limit 20"
      warnings: "fields @timestamp, @message | filter @message like /warn/ | sort @timestamp desc | limit 20"

Queries can be customized according to your needs, using the CloudWatch Logs Insights syntax.

Usage

Run queries directly through the Serverless Framework CLI:

sls logs-insights -f <function> -q <query> [-i <interval>]

Available Options

Option Description
-f, --function Name of the Lambda function (as defined in serverless.yml)
-q, --query Name of the query defined in custom.logsInsights.queries or a free query
-i, --interval Time interval (default: 1h)

Examples

Query the latest errors of a Lambda function named hello:

sls logs-insights -f hello -q errors

Run a custom query directly via CLI:

sls logs-insights -f hello -q "fields @message | filter @message like /timeout/" -i 3h

How does it work?

The plugin uses the AWS SDK to execute queries in CloudWatch Logs Insights, retrieving events from the log groups associated with the Lambda functions in your Serverless project. Results are displayed directly in the terminal in a user-friendly manner.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Developed by Kauê Leal - github.com/kauelima21

About

Serverless Framework plugin to run AWS CloudWatch Logs Insights queries directly from the CLI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published