Add rules to a gateway
Gateway rules let you control traffic routing and override target configurations on your gateway without redeploying targets. You create configuration bundles that override a target’s behavior, then use rules to control which bundle version applies to which traffic. Rules also support routing requests to different targets based on request path or caller identity.
Use gateway rules to accomplish the following goals:
-
Experiment with configuration bundle versions through A/B testing
-
Pin specific principals to a configuration bundle version for debugging
-
Route traffic to specific targets based on request path or caller identity
-
Set a default configuration bundle or target for all traffic
How gateway rules work
Each gateway rule contains the following components:
| Component | Description |
|---|---|
|
Priority |
An integer from 1 to 1,000,000. Lower numbers indicate higher precedence. Each priority value must be unique within a gateway. |
|
Conditions (optional) |
Criteria that determine whether the rule matches a request. A rule without conditions acts as a catch-all that matches all traffic. |
|
Actions (required) |
The action to take when the rule matches. You can override configuration bundles, route to specific targets, or both. |
|
Description (optional) |
A text description of the rule’s purpose. |
Rule resolution
The gateway evaluates rules in ascending priority order (lower numbers first). The gateway resolves each action type independently using first-match semantics.
The following table shows how the gateway resolves rules for a sample request. In this example, the QA role sends a request to /my-target-canary/chat.
| Priority | Conditions | Actions | Matches request? | Result |
|---|---|---|---|---|
|
100 |
QA role |
|
Yes |
Resolves |
|
200 |
Path |
|
Yes |
Resolves |
|
1000000 |
None (catch-all) |
|
Yes |
Both action types already resolved. Skipped. |
Final result: The request uses bundle version A and routes to my-target-canary.
Tip
Leave gaps between priority numbers (for example, 100, 200, 300) so that you can insert rules later without renumbering existing rules.
Conditions
Conditions determine which requests a rule matches. A rule can have a maximum of 2 conditions. A rule with no conditions matches all traffic.
The gateway supports the following condition types:
- matchPrincipals
-
Matches requests based on the caller’s IAM principal. The
anyOflist contains 1 to 100 entries. Each entry specifies aniamPrincipalwith the following fields:-
arn— The IAM principal ARN to match. -
operator(optional) — The comparison operator. Valid values areStringEquals(default) andStringLike. UseStringLikefor wildcard matching.
-
- matchPaths
-
Matches requests based on the request path. The
anyOflist contains 1 to 10 entries. Each entry must use the format/<targetName>/*, where<targetName>matches the name of an existing HTTP target on the gateway. The target must be inReadystate. ThematchPathscondition is supported only for gateways with HTTP targets. The following reserved path prefixes are not allowed:/mcp,/a2a,/responses,/converse,/.well-known.
Condition evaluation logic
-
Within a condition type: The gateway uses OR logic. A request matches if it satisfies any entry in the
anyOflist. -
Across condition types: The gateway uses AND logic. If a rule has both
matchPrincipalsandmatchPaths, the request must match at least one entry from each condition type.
Actions
Actions define what the gateway does when a rule matches. A rule can have a maximum of 2 actions.
The gateway supports the following action types:
-
Configuration bundle overrides (
configurationBundle) -
Override the configuration bundle applied to matching traffic.
-
staticOverride— Pins all matching traffic to a specific configuration bundle version. Specify the bundle ARN and version ID. -
weightedOverride— Splits traffic between two configuration bundle versions. ThetrafficSplitlist must contain exactly 2 entries with weights that sum to 100. The configuration bundle must be in the same account as the gateway.
-
-
Target routing (
routeToTarget) -
Routes matching traffic to a specific target. The target must use the HTTP protocol and be in
Readystate.-
staticRoute— Routes all matching traffic to a specific target by name. -
weightedRoute— Splits traffic between two targets. ThetrafficSplitlist must contain exactly 2 entries with weights that sum to 100. Traffic split entry names must be unique.
-
Limits
The following table lists the limits for gateway rules.
| Resource | Limit |
|---|---|
|
Rules per gateway |
20 |
|
Priority range |
1 to 1,000,000 |
|
Maximum conditions per rule |
2 |
|
Maximum actions per rule |
2 |
|
|
100 |
|
|
10 |
|
|
Exactly 2 |
|
|
1 to 99 |