npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

patrol

v0.0.1

Published

Run scheduled rules on AWS Lambda

Downloads

6

Readme

Patrol

A lightweight, general purpose, serverless monitoring framework for security, compliance, and best practice issues across an organization. It simplifies wiring arbitrary event streams to logic and notifications.

Patrol is a Node application deployed on AWS, leveraging the following AWS services:

Patrol can consume event streams from non-AWS sources and provides three types of rule triggers:

  • CloudWatch Event Rules
  • Scheduled rules
  • SNS subscriptions

General Anatomy of a Patrol stack

Patrol

Patrol itself ties together lambda-cfn and repositories containing rulesets (patrol-rules-aws). The patrol repository is an example only, please fork to maintain your own custom Patrol stack.

It requires cfn-config to deploy the javascript CloudFormation template.

Rulesets are added to the patrol/package.json, allowing rulesets to be independently version controlled in their own repositories.

Rules compiled into the Patrol lambda are defined in patrol/cloudformation/patrol.template.js.

lambda-cfn

lambda-cfn is a reusable framework to generate Lambda functions. It does most of the heavy lifting, creating both the CloudFormation template and the CloudWatch Event Rules.

cfn-config

cfn-config provides a interactive commandline tool to create and update CloudFormation templates. It supports the Javascript CloudFormation templates necessary for Patrol.

patrol-rules-aws

Public Patrol rules for monitoring AWS resources and API calls.

streambot

streambot provides a wrapper function and a backend to load CloudFormation parameters into a lambda's environment.

Using Patrol

Patrol in action

The disallowedResources.js rule from patrol-rules-aws uses CloudTrail to generate an alert when a policy document grants access to specific resource ARNs.

   +------------------+
   | CloudTrail Event |
   |      Stream      |
   +--------+---------+
            |
            |     Patrol managed resources
+-------------------------------------------+
|           |                               |
|     +-----v-----------+                   |
|     | CloudWatch Rule |                   |
|     +--------+--------+                   |
|              |                            |
|              | Run event against          |     +-----------+
|              |                            |     | Streambot |
|      +-------v-------+                    |     +------^----+
|      | event pattern |                    |            |
|      +-------+-------+                    |            |
|              |                            |            |
|              | on match, trigger          |            |
|              |                            |            |
|      +-------v--------------------+       |            |
|      | Subscribed Lambda function <--------------------+
|      +-------------+--------------+       |      get parameters
|                    |                      |
|                    |                      |
|      +-------------v---------+            |
|      | process event payload |            |
|      +---+-------------------+            |
|          |                                |
|          |                                |
|          | emit message to SNS topic      |
|          |                                |
|          |                                |
|     +----v------+                         |
|     | SNS topic |                         |
|     +---------+-+                         |
|               |                           |
+-------------------------------------------+
                |
                |
            +---v-------+
            | PagerDuty |
            +-----------+

Rule walkthrough

disallowedResources.js

  1. The rule requires a comma separated list of ARNs, specified during template deployment by the parameter config.parameters.disallowedResourceArns.
  2. The config.eventRule object describes the CloudWatch Event Rule, the source for the rule (CloudTrail), and the rule filter pattern. See CloudWatch Events and Event Patterns for more on the syntax of event patterns.
  3. When the rule pattern is matched, CloudWatch Rules triggers the Patrol Lambda and passes the event to the index.disallowedResources handler.
  4. The rule function defined in module.rule.fn and bound to the index.disallowedResources handler processes the event, and the function emits a message to an SNS topic when appropriate.