Amazon EventBridge
API Reference (API Version 2015-10-07)

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above.

PutRule

Creates or updates the specified rule. Rules are enabled by default or based on value of the state. You can disable a rule using DisableRule.

A single rule watches for events from a single event bus. Events generated by AWS services go to your account's default event bus. Events generated by SaaS partner services or applications go to the matching partner event bus. If you have custom applications or services, you can specify whether their events go to your default event bus or a custom event bus that you have created. For more information, see CreateEventBus.

If you're updating an existing rule, the rule is replaced with what you specify in this PutRule command. If you omit arguments in PutRule, the old values for those arguments aren't kept. Instead, they're replaced with null values.

When you create or update a rule, incoming events might not immediately start matching to new or updated rules. Allow a short period of time for changes to take effect.

A rule must contain at least an EventPattern or ScheduleExpression. Rules with EventPatterns are triggered when a matching event is observed. Rules with ScheduleExpressions self-trigger based on the given schedule. A rule can have both an EventPattern and a ScheduleExpression, in which case the rule triggers on matching events as well as on a schedule.

When you initially create a rule, you can optionally assign one or more tags to the rule. Tags can help you organize and categorize your resources. You can also use them to scope user permissions, by granting a user permission to access or change only rules with certain tag values. To use the PutRule operation and assign tags, you must have both the events:PutRule and events:TagResource permissions.

If you are updating an existing rule, any tags you specify in the PutRule operation are ignored. To update the tags of an existing rule, use TagResource and UntagResource.

Most services in AWS treat : or / as the same character in Amazon Resource Names (ARNs). However, EventBridge uses an exact match in event patterns and rules. Be sure to use the correct ARN characters when creating event patterns so that they match the ARN syntax in the event that you want to match.

In EventBridge, you could create rules that lead to infinite loops, where a rule is fired repeatedly. For example, a rule might detect that ACLs have changed on an S3 bucket, and trigger software to change them to the desired state. If you don't write the rule carefully, the subsequent change to the ACLs fires the rule again, creating an infinite loop.

To prevent this, write the rules so that the triggered actions don't refire the same rule. For example, your rule could fire only if ACLs are found to be in a bad state, instead of after any change.

An infinite loop can quickly cause higher than expected charges. We recommend that you use budgeting, which alerts you when charges exceed your specified limit. For more information, see Managing Your Costs with Budgets.

Request Syntax

{ "Description": "string", "EventBusName": "string", "EventPattern": "string", "Name": "string", "RoleArn": "string", "ScheduleExpression": "string", "State": "string", "Tags": [ { "Key": "string", "Value": "string" } ] }

Request Parameters

For information about the parameters that are common to all actions, see Common Parameters.

The request accepts the following data in JSON format.

Description

A description of the rule.

Type: String

Length Constraints: Maximum length of 512.

Required: No

EventBusName

The event bus to associate with this rule. If you omit this, the default event bus is used.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 256.

Pattern: [/\.\-_A-Za-z0-9]+

Required: No

EventPattern

The event pattern. For more information, see Event Patterns in the Amazon EventBridge User Guide.

Type: String

Required: No

Name

The name of the rule that you're creating or updating.

A rule can't have the same name as another rule in the same Region or on the same event bus.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 64.

Pattern: [\.\-_A-Za-z0-9]+

Required: Yes

RoleArn

The Amazon Resource Name (ARN) of the IAM role associated with the rule.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 1600.

Required: No

ScheduleExpression

The scheduling expression: for example, "cron(0 20 * * ? *)" or "rate(5 minutes)".

Type: String

Length Constraints: Maximum length of 256.

Required: No

State

Indicates whether the rule is enabled or disabled.

Type: String

Valid Values: ENABLED | DISABLED

Required: No

Tags

The list of key-value pairs to associate with the rule.

Type: Array of Tag objects

Required: No

Response Syntax

{ "RuleArn": "string" }

Response Elements

If the action is successful, the service sends back an HTTP 200 response.

The following data is returned in JSON format by the service.

RuleArn

The Amazon Resource Name (ARN) of the rule.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 1600.

Errors

For information about the errors that are common to all actions, see Common Errors.

ConcurrentModificationException

There is concurrent modification on a resource.

HTTP Status Code: 400

InternalException

This exception occurs due to unexpected causes.

HTTP Status Code: 500

InvalidEventPatternException

The event pattern isn't valid.

HTTP Status Code: 400

LimitExceededException

You tried to create more resources than is allowed.

HTTP Status Code: 400

ManagedRuleException

An AWS service created this rule on behalf of your account. That service manages it. If you see this error in response to DeleteRule or RemoveTargets, you can use the Force parameter in those calls to delete the rule or remove targets from the rule. You can't modify these managed rules by using DisableRule, EnableRule, PutTargets, PutRule, TagResource, or UntagResource.

HTTP Status Code: 400

ResourceNotFoundException

An entity that you specified doesn't exist.

HTTP Status Code: 400

Example

Creates a rule named "test" that matches events from Amazon EC2. The rule is also given two tags.

The following is an example of a PutRule request and response.

Sample Request

POST / HTTP/1.1 Host: events.<region>.<domain> x-amz-Date: <Date> Authorization: AWS4-HMAC-SHA256 Credential=<Credential>, SignedHeaders=content-type;date;host;user-agent;x-amz-date;x-amz-target;x-amzn-requestid, Signature=<Signature> User-Agent: <UserAgentString> Content-Type: application/x-amz-json-1.1 Content-Length: <PayloadSizeBytes> Connection: Keep-Alive X-Amz-Target: AWSEvents.PutRule { "Name": "test", "EventPattern": "{ \"source\": [\"aws.ec2\"] }", "Tags": [ { "Key": "Stack", "Value": "Prod" }, { "Key": "CostCenter", "Value": "12345" } ] }

Sample Response

HTTP/1.1 200 OK x-amzn-RequestId: <RequestId> Content-Type: application/x-amz-json-1.1 Content-Length: <PayloadSizeBytes> Date: <Date> { "RuleArn": "arn:aws:events:us-east-1:123456789012:rule/test" }

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: