• Stars
    star
    214
  • Rank 184,678 (Top 4 %)
  • Language
    JavaScript
  • Created almost 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pattern generator and debugging tool for Amazon EventBridge

Node.js CI

evb-cli

Pattern generator and debugging tool for EventBridge

Installation

npm install -g @mhlabs/evb-cli

Usage

To generate an EventBridge pattern:

evb pattern - Will prompt you with a wizard that helps you build pattern for event matching. This is using EventBridge's schema registry (currently in preview) to let you navigate the schema you want to react on.

evb pattern --format <yaml|json> - Output format. Default is json

For AWS events, such as aws.codepipeline it's already enabled, but for custom events you will have to enable it in the AWS Management Console.

Demo

Generate EventBridge Pipes connections

EventBridge Pipes was one of the more exciting serverless announcements at re:Invent 2022. It lets you create a one-to-one mapping between a source and a target service so you can build event driven applications with less Lambda glue functions.

evb pipes helps you create pipes between resources in your CloudFormation/SAM template. Although the AWS::Pipes::Pipe resource is easy to compose, the IAM role that goes with it isn't that straight forward.

Use the --guided flag to get prompted for all optional parameters.

Demo

To generate an EventBridge InputTransformer object:

Input transformers are useful when you only want a small portion of the event sent to your target. This command helps you navigate the JSON payload and generate the InputTransformer CloudFormation object

evb input will prompt you with a wizard that helps you build the InputTransformer object. This is using EventBridge's schema registry (currently in preview).

evb input --format <yaml|json> - Output format. Default is json

Demo

To browse targets of events:

Select a schema from the schema registry and list its targets. Select a target to browse details such as ARN, event pattern, input transformation, etc.

evb browse will let you browse your schemas and get insights into the targets listening to the source/detail-type combination of your event. This only works with explicit matching on source and detail-type.

Demo

To generate an interactive diagram over the event rules of an eventbus

Usage: evb diagram|d [options]

Builds an interactive diagram over an eventbus' rules 

Options:
  -b, --eventbus [eventbus]  Eventbus to create diagram for (default: "default")
  -p, --profile [profile]    AWS profile to use
  -h, --help                 output usage information

Demo

This is an experimental feature. Grouping by tag is possible for the following target types: Lambda, StepFunctions, SNS, SQS, Kinesis. More will follow.

Extract AWS::Serverless::Function Event to AWS::Events::Rule

Sometimes you start off with a simple EventBridgeRule transform on you AWS::Serverless::Function resource. Later on you might want to evolve it and start using an InputTransformer or retry/DLQ configurations which is only supported by AWS::Events::Rule

Use evb extract-sam-event to unfold the SAM event to full CloudFormation syntax.

Test event payload against all rules on a bus

Usage: evb test-event|t [options]

Tests an event payload against existing rules on a bus

Options:
  -e, --event-input-file [event-file]  Path to test event (default: "event.json")
  -n, --name-prefix [name-prefix]      Name prefix for rules; helpful to narrow against one or a few rules only
  -b, --eventbus [eventbus]            The eventbus to test against (default: "default")
  -a, --all                            Show all rules, even unmatched ones (default: false)

Example event input can be found here

Generate code bindings

Usage: evb code-binding|cb [options]

Generates code bindings from the schema registry based on the defined InputPath or InputTransformer

Options:
  -t, --template [template]       Path to template file
  -n, --type-name [typeName]      Type name (default: "MyType")
  -o, --output-file [outputFile]  Output file name. Writes to std out if skipped
  -l, --language [language]       Output language
  -h, --help                      output usage information

Demo)

If --template is provided, the tool will parse your template and generate code bindings that match the InputPath or InputTransformer that is defined.

If no template is passed to the command, then you will get prompted to select a schema from the registry.

This is using quicktype. See their docs for target languages

Find usages in event rule patterns

Usage: evb find-usages|f [options]

Searches all rules on a bus for matching event patterns.

I.e to find all rules that match on an s3:PutObject event from CloudTrail, use:
evb find-usages -f $.source=aws.s3,$.detail-type=.+CloudTrail,$.detail.eventName=PutObject

Options:
  -b, --eventbus [eventbus]  Name of the event bus to search. (default: "default")
  -f, --filters [filters]    Comma separated list of '$.path.to.property=regex-pattern' to filter the event patterns with
  -p, --profile [profile]    AWS profile to use
  --region [region]          The AWS region to use. Falls back on AWS_REGION environment variable if not specified
  -h, --help                 output usage information

This command allows you to find usages of specific fields across all event rules on a bus. This could be useful in order to find individual consumers of a specific field in your event payload.

Some examples:

  • Find all rules that match on a specific source and detail-type combination on a custom bus: evb find-usages --filters $.source=my-custom-source,$.detail-type=my-custom-detail-type --eventbus custombus
  • Find all rules that trigger on any of AWS CodePipeline, CodeBuild, CodeDeploy, etc events: evb find-usages --filters $.source=aws\.code.*
  • Find all rules that trigger on a Lambda failure destination: evb find-usages --filters $.detail-type='Lambda Function Invocation Result - Failure'

Generate API Destinations resources

Usage: evb api-destination|api [options]

Generates API Destination SAM template resources

Options:
  -t, --template [template]  Path to template file (default: "template.yaml")
  -p, --profile [profile]    AWS profile to use
  --region [region]          The AWS region to use. Falls back on AWS_REGION environment variable if not specified
  -u --url [url]             URL to OpenAPI specification of API

Pass a URL to OpenAPI specification of an API and the tool will generate SAM template resources for API Destination resources. It will guide you through the third party OpenAPI schema and let you build mappings between their parameters and your event payload.

Supports OpenAPI 2 and 3.

Demo)

Example of creating a an API Destination that posts codepipeline status updates to Slack

Replay events

Usage: evb replay|r [options]

Starts a replay of events against a specific destination

Options:
  -b, --eventbus [eventbus]       The eventbus the archive is stored against (default: "default")
  -r, --rule-prefix [rulePrefix]  Rule name prefix
  -p, --profile [profile]         AWS profile to use
  -s, --replay-speed [speed]      The speed of the replay in % where 0 == all at once and 100 == real time speed
  -n, --replay-name [name]        The replay name (default: "evb-cli-replay-1605913422337")
  --region [region]               The AWS region to use. Falls back on AWS_REGION environment variable if not specified
  -h, --help                      output usage information

Paced replays

** Requires evb local >= v0.0.7 **

Evb-cli provides support for paced replay delivery where you can pass a replay speed scalar between 0 and 100 where 0 is as fast as possible (native EventBridge way) and 100 is real time speed where a one hour replay takes one hour. Passing --replay-speed 10 to a one hour replay will scale the replay speed to 6 minutes, but will still retain the same order and a scaled delay between messages.

Currently EventBridge will run your replay at the fastest possible speed. Due to the unordered nature of EventBridge, this means there's an increased likelyhood that your events will be delivered more randomly during a replay than when live.

Your EventBridge targets should always be idempotent, but for debugging purposes you might want the likely order of the events.

For example, you might replay 5 hours of order events and want to expect each order to transition from OPEN to CONFIRMED to DELIVERED in the logical order. If you run a default replay it's likely that these events will be delivered in the wrong order.

Pricing

When using --replay-speed > 0, each event in the replay will be sent through a Step Functions state machine of 5 state transitions. See Step Functions pricing for you region.

Caveats

  • At delivery, the replay-name field will be stripped.
  • Step Functions is used to pace the replay. EventBridge will consider the replay a success as long as the events were delivered to Step Functions.

Local debugging

Local debugging makes use to API Gateway V2 websockets to forward actual events in the cloud to your developer machine. The requires a Serverless Application Repository app to be installed in your account. Note that depending on your traffic, there will be some small effect on your billing in the form of Lambda invocations, API Gateway invocations, CloudWatch Logs and DynamoDB R/W.

Demo

Example of testing a rule before deploying the stack. The user quickly gets feedback on their patterns and input transforms. In this example we're listening to all aws.* events and transforming the output to

{
  "source": <source>,
  "time": <time>
}

The user then decided to add detail-type to the transform:

{
  "source": <source>,
  "detail-type": <detail-type>,
  "time": <time>
}

There are three methods of consuming events covering three use cases:

Listen to all deployed rules in a given stack

Command: evb local --stack-name <stack-name> Use case: You have a deployed stack and want to analyse the events matching any rule in the stack. Useful if you want to real-time monitor actual behaviour of the application.

Test a rule before deploying the stack

Command: evb local --rule <rule logical id (optional)> Use cases:

  • You want to test a pattern or input transformation without deploying the entire stack. This speeds up trial and error resolutions.
  • You want to analyse traffic for a given pattern over time If the rule's logical ID is omitted such as evb local --rule the tool will parse the template and let you navigate and choose the rule

Test a given ARN on a deployed stack

Command: evb local --arn <rule-arn> Use cases:

  • You want to test the behaviour of an already deployed rule where you don't know the stack's name or where it doesn't belong to a stack.

Replaying archived events

Add --replay option to command. This will guide you through a wizard to find the archive and set the time range to replay.

Note that this currently only works together with the -t flag and it requires at least v0.0.8 of the evb-local backend

Forward events to sam-local

All evb local commands support a --sam-local flag. When used, events will be passed on to sam-local for more advanced debugging

More Repositories

1

cfn-diagram

CLI tool to visualise CloudFormation/SAM/CDK stacks as visjs networks, draw.io or ascii-art diagrams.
JavaScript
901
star
2

cw-logs-insights-gpt

Chrome extension that generates CloudWatch Logs Insights queries from ChatGPT prompts
JavaScript
89
star
3

samp-cli

CLI tool that offers advanced productivity and debugging features to AWS SAM users
JavaScript
70
star
4

iam-policies-cli

A CLI tool for building simple to complex IAM policies
JavaScript
68
star
5

sfn-workflow-studio-sync

Enables real-time sync between StepFunctions Workflow Studio and your local machine
JavaScript
42
star
6

lambda-debug

Library to help debug JS/TS AWS Lambda functions locally
JavaScript
32
star
7

cfn-resource-actions

Interact with your deployed CloudFormation/SAM templates directly from the template
TypeScript
22
star
8

awesome-lars-tools

Consolidated list of the tools I maintain
13
star
9

cw-logs-insights-snippets

AWS SAM project that adds the snippets from serverlessland.com/snippets as saved queries in CloudWatch Logs Insights
TypeScript
12
star
10

aws-resource-explorer-cli

Searches AWS resources and launches them in the AWS console in your browser
JavaScript
9
star
11

low-code-url-shortener

Low code URL shortener build on AWS API Gateway, StepFunctions Express and DynamoDB
7
star
12

ai-doorbell

AI doorbell that uses speech synthesis to describe the person at the door
JavaScript
7
star
13

stepfunctions-sdk-autocomplete

VSCode autocomplete for AWS StepFunctions SDK integrations
TypeScript
5
star
14

aws-news-comics

Bot that creates comic strips from the latest service announcements from AWS and posts them on X
JavaScript
2
star
15

evb-sfn-event-scheduler

JavaScript
2
star
16

github-codesearch-chrome-extension

Chrome extension lets you make select text on any webpage and search for it in GitHub CodeSearch
JavaScript
2
star
17

cloudwatch-logs-snippets-extension

Chrome extension that gives instant access to the CloudWatch Logs Insights snippets from serverlessland.com/snippets
JavaScript
2
star
18

cw-alarms-poc

Reference project for loosely coupled cloudwatch alarms
JavaScript
1
star
19

reinvent-portal-extension

Chrome extension to help getting a seat at your favourite sessions at re:invent
JavaScript
1
star