Skip to content
GitHubXDiscord

EventRule

The EventRule resource lets you manage AWS Notifications EventRules to automate notifications based on specific events.

Create a basic EventRule that listens for a specific event type and pattern.

import AWS from "alchemy/aws/control";
const eventRule = await AWS.Notifications.EventRule("basicEventRule", {
EventType: "AWS::SNS::Notification",
NotificationConfigurationArn: "arn:aws:sns:us-east-1:123456789012:MyTopic",
Regions: ["us-east-1"],
Source: "aws:s3"
});

Configure an EventRule with an event pattern to filter specific notifications.

const advancedEventRule = await AWS.Notifications.EventRule("advancedEventRule", {
EventType: "AWS::SNS::Notification",
NotificationConfigurationArn: "arn:aws:sns:us-west-2:123456789012:MyTopic",
Regions: ["us-west-2"],
Source: "aws:ec2",
EventPattern: JSON.stringify({
"source": ["aws.ec2"],
"detail-type": ["EC2 Instance State-change Notification"],
"detail": {
"state": ["running"]
}
})
});

Adopt an existing EventRule without failing if it already exists in the specified region.

const adoptEventRule = await AWS.Notifications.EventRule("adoptEventRule", {
EventType: "AWS::SNS::Notification",
NotificationConfigurationArn: "arn:aws:sns:us-east-1:123456789012:MyExistingTopic",
Regions: ["us-east-1"],
Source: "aws:lambda",
adopt: true
});

Set up an EventRule that can listen for events across multiple regions.

const multiRegionEventRule = await AWS.Notifications.EventRule("multiRegionEventRule", {
EventType: "AWS::SNS::Notification",
NotificationConfigurationArn: "arn:aws:sns:us-east-1:123456789012:MyMultiRegionTopic",
Regions: ["us-east-1", "us-west-1", "us-west-2"],
Source: "aws:s3",
EventPattern: JSON.stringify({
"source": ["aws.s3"],
"detail-type": ["AWS API Call via CloudTrail"],
"detail": {
"eventSource": ["s3.amazonaws.com"],
"eventName": ["PutObject"]
}
})
});