Rule
Source:
src/AWS/EventBridge/Rule.ts
An Amazon EventBridge rule that matches events and routes them to targets.
Creating Rules
Section titled “Creating Rules”Event Pattern Rule
const rule = yield* Rule("S3Events", { eventPattern: { source: ["aws.s3"], "detail-type": ["Object Created"], }, targets: [{ Id: "MyTarget", Arn: yield* queue.queueArn, }],});Scheduled Rule
const rule = yield* Rule("EveryFiveMinutes", { scheduleExpression: "rate(5 minutes)", targets: [{ Id: "LambdaTarget", Arn: yield* fn.functionArn(), }],});Targeting
Section titled “Targeting”Rule with Input Transformer
const rule = yield* Rule("TransformedEvents", { eventPattern: { source: ["aws.ec2"], "detail-type": ["EC2 Instance State-change Notification"], }, targets: [{ Id: "SqsTarget", Arn: yield* queue.queueArn, InputTransformer: { InputPathsMap: { instance: "$.detail.instance-id", state: "$.detail.state", }, InputTemplate: '{"instanceId": <instance>, "newState": <state>}', }, }],});Rule with Dead Letter Queue
const rule = yield* Rule("ReliableEvents", { eventPattern: { source: ["my.app"] }, targets: [{ Id: "Target", Arn: yield* fn.functionArn(), DeadLetterConfig: { Arn: yield* dlq.queueArn, }, RetryPolicy: { MaximumRetryAttempts: 3, MaximumEventAgeInSeconds: 3600, }, }],});Rule with ECS Target
const rule = yield* Rule("EcsSchedule", { scheduleExpression: "rate(1 hour)", roleArn: yield* role.roleArn(), targets: [{ Id: "EcsTask", Arn: yield* cluster.clusterArn(), RoleArn: yield* ecsRole.roleArn(), EcsParameters: { TaskDefinitionArn: yield* taskDef.taskDefinitionArn(), TaskCount: 1, LaunchType: "FARGATE", NetworkConfiguration: { awsvpcConfiguration: { Subnets: ["subnet-abc123"], AssignPublicIp: "ENABLED", }, }, }, }],});