Skip to main content
In this demo you’ll learn how to use Amazon EventBridge to generate, route, and act on events in your AWS account — for example EC2 instance state changes — and how to emit and route custom application events. We cover event buses, rules, event patterns, and targets (Lambda, SNS, SQS, etc.), plus a minimal Node.js example that emits custom events. What you’ll learn:
  • How EventBridge event buses isolate and receive events.
  • How rules match events and route them to targets.
  • How to build event patterns for AWS services (EC2) and custom events.
  • How to test events end-to-end using Lambda and CloudWatch Logs.
Key EventBridge concepts Event buses EventBridge provides a default event bus for your account; you can create custom buses to isolate apps or teams. For this demo we use the default event bus — the workflow is identical for custom buses.
A screenshot of the Amazon Web Services EventBridge console showing the "Event buses" page with a Default event bus listed and options like Start discovery, Create archive, Send events, and a prominent "Create event bus" button. The left sidebar shows other EventBridge sections (Rules, Archives, Pipes, Scheduler).
Creating rules Rules define which events should be routed to which targets. In this demo we create a rule that triggers on EC2 instance state changes. Start by creating a rule: give it a name and description, and select the event bus (default in this demo).
A screenshot of the AWS Management Console showing the Amazon EventBridge "Create rule" page, specifically the "Define rule detail" step with the rule name set to "instance-status-change," event bus selection, and rule type options. A blue informational banner appears at the top.
Rule types
  • Event pattern — Runs when an incoming event matches the JSON pattern.
  • Schedule — Runs on a cron-like schedule for time-based triggers.
Build event patterns EventBridge supports several ways to author event patterns:
  • Schema discovery (discover shapes of AWS events)
  • Pattern form (guided form by service and event type)
  • Custom JSON (paste or author your own JSON)
Sample AWS service payloads (examples) help you identify fields you can match against when building patterns. For example, a sample AWS S3 Object Created event looks like this (illustrative only):
Note: sample events show the fields available for matching when constructing your event pattern. Selecting EC2 instance state changes Use the pattern form to match EC2 instance state-change notifications. In the pattern form you choose:
  • The AWS service (EC2)
  • The event type (EC2 Instance State-change Notification)
  • Optional filters such as specific state(s) (shutting-down, stopped, terminated) or specific instance IDs
A screenshot of the AWS Management Console (EventBridge) "Create rule" page showing the "Creation method" with "Use pattern form" selected. An event-type dropdown is open listing options such as "EC2 Instance State-change Notification."
Example custom event pattern JSON that matches EC2 instance state-change notifications for a shutting-down state:
If you want to match all state changes, omit the detail.state key so the rule matches any EC2 state change. Choosing targets After defining the pattern, attach one or more targets to receive matched events. Common targets include Lambda, SNS, SQS, Step Functions, and ECS tasks. You can add multiple targets to run different actions in response to the same event. Example Lambda ARN shown in the console: arn:aws:lambda:us-east-1:841860927337:function:test1 Lambda handler (example) For testing, have your Lambda log the incoming event payload. A minimal Node.js handler that prints the event:
After you create the rule and attach the Lambda target, generate a matching event (for example, stop an EC2 instance) and inspect the Lambda’s CloudWatch Logs to verify it was invoked and received the event. Open the Lambda console and use Monitor > View logs in CloudWatch to inspect log streams.
A screenshot of the AWS Lambda console showing the function "test1" overview. The Monitor tab is open, displaying CloudWatch metrics panels like Invocations, Duration, and error/success rates.
A shortened example of the EC2 event your Lambda might log:
This confirms EventBridge matched the EC2 state-change event and routed it to the Lambda target. Emit custom events from your application EventBridge can ingest custom application events in addition to AWS service events. This enables loosely-coupled, event-driven architectures where apps emit events and EventBridge routes them to the right consumers. What this document includes:
  1. A minimal Node.js/Express example that emits an EventBridge event on user signup.
  2. Instructions for creating an EventBridge rule to match that custom event.
  3. Steps to verify the Lambda target received the custom event.
Dependencies Install the required packages:
Application code to emit custom events Below is a concise Express server that sends events to the default event bus using AWS SDK v3:
Important fields when emitting custom events:
  • Source — free-form identifier for the event source (e.g., "my-app").
  • DetailType — describes the kind of event (e.g., "New User").
  • Detail — a JSON string containing the event payload.
Create an EventBridge rule to match custom events Create a rule that matches your custom events with a JSON pattern. For the example app above, a minimal pattern to match Source my-app and DetailType New User looks like this:
Attach one or more targets (for example, a Lambda function test2) so that when your application emits the event, EventBridge routes it to the Lambda.
A screenshot of the AWS EventBridge console on the "Select target(s)" step for creating a rule, showing "AWS service" selected and a Lambda function named "test2" set as Target 1. The left sidebar shows the rule-creation steps and action buttons (Add another target, Skip to Review and create, Next) appear along the bottom.
Testing custom events from the console You can send a test event from the EventBridge console (Send events) to validate your rule/target before integrating with the application. Example test detail used in this demo:
When EventBridge delivers this test event to the Lambda target, the Lambda log contains an event similar to:
Testing the application end-to-end Start your Express server and send a POST to /signup: Example curl request:
Server response:
After a few seconds, check the CloudWatch Logs for your Lambda target. You should see the event printed, confirming the event was emitted by your app, routed by EventBridge, and received by the Lambda:
Summary
  • EventBridge ingests both AWS service events and custom application events.
  • Use event rules to match patterns and route events to one or more targets.
  • Lambda is a common, lightweight target for processing, forwarding, or debugging events.
  • Custom events enable decoupled, event-driven architectures across applications and AWS services.
Resources and links
Use the EventBridge pattern form and sample events to explore available fields for different AWS services — this makes it easier to build precise matching rules without guessing the event shape.

Watch Video