Tutorial: Create a rule with an event pattern
The following procedure covers how to create a rule with an event pattern.
To create a rule that sends the event to a target when the event matches a defined pattern
Note
This procedure works for all AWS Batch on Amazon ECS, Amazon EKS, and AWS Fargate jobs.
Open the Amazon EventBridge console at https://console.aws.amazon.com/events/
. -
From the navigation bar, select the AWS Region to use.
-
In the navigation pane, choose Rules.
-
Choose Create rule.
-
For Name, specify a unique name for your compute environment. The name can contain up to 64 characters. It can contain uppercase and lowercase letters, numbers, hyphens (-), and underscores (_).
Note
A rule can't have the same name as another rule in the same Region and on the same event bus.
-
(Optional) For Description, enter a description for the rule.
-
For Event bus, choose the event bus that you want to associate with this rule. If you want this rule to match events that come from your account, select default. When an AWS service in your account emits an event, it always goes to your account's default event bus.
-
(Optional) Turn off the rule on the selected bus if you don't want to run the rule immediately.
-
For Rule type, choose Rule with an event pattern.
-
Choose Next.
-
For Event Source, choose AWS event or EventBridge partner events.
-
(Optional) For Sample event:
-
For Sample event type, choose AWS events.
-
For Sample events, choose Batch Job State Change.
-
-
For Creation method, choose Use pattern form.
-
For Event pattern:
-
For Event source, choose AWS services.
-
For AWS service, choose Batch.
-
For Event type, choose Batch Job State Change.
-
-
Choose Next.
-
For Target types, choose AWS service.
-
For Select a target, choose a target type. For example, choose Batch job queue. Then specify the following:
-
Job queue: Enter the Amazon Resource Name (ARN) of the job queue to schedule your job in.
-
Job definition: Enter the name and revision or full ARN of the job definition to use for your job.
-
Job name: Enter a name for your job.
-
Array size: (Optional) Enter an array size for your job to run more than one copy. For more information, see Array jobs.
-
Job attempts: (Optional) Enter the number of times to retry your job if it fails. For more information, see Automated job retries.
-
-
For Batch job queue target types, EventBridge needs permission to send events to the target. EventBridge can create the IAM role needed for your rule to run. Do one of the following:
-
To create an IAM role automatically, choose Create a new role for this specific resource.
-
To use an IAM role that you created before, choose Use existing role.
-
-
(Optional) Expand Additional settings.
-
For Configure target input, choose how text from an event is processed.
-
For Maximum age of event, specify the time interval for how long unprocessed events are kept.
-
For Retry attempts, enter the number of times that an event is retried.
-
For Dead-letter queue, choose an option for how unprocessed events are handled. If necessary, specify the Amazon SQS queue to use as the dead-letter queue.
-
-
(Optional) Choose Add another target to add an additional target.
-
Choose Next.
-
(Optional) For Tags, choose Add new tag to add a resource label. For more information, see Amazon EventBridge tags in the Amazon EventBridge User Guide.
-
Choose Next.
-
For Review and create, review the configuration steps. If you need to make changes, choose Edit. After you're finished, choose Create rule.
For more information about creating rules, see Creating Amazon EventBridge rules that react to events in the Amazon EventBridge User Guide.