Elastic Load Balancing · Networking

ListenerRule

Manage listener routing rules, conditions, and priority.

Generic driverUniform lifecycle
Scope
Composite
Spec fields
7
Outputs
2
Lookup
Supported

Resource definition

What this resource looks like

This is the CUE shape a Praxis template uses to declare a ListenerRule. The resource key is local to the template; metadata.name supplies its stable Praxis identity.

CUE example
resources: {
  apiListenerRule: {
  	apiVersion: "praxis.io/alpha"
  	kind:       "ListenerRule"
  	metadata: name: "\(_naming.prefix)-api-rule"
  	spec: {
  		region:      _naming.region
  		listenerArn: "${resources.httpsListener.outputs.listenerArn}"
  		priority:    100
  		conditions: [{
  			field:  "path-pattern"
  			values: ["/api/*"]
  		}]
  		actions: [{
  			type:           "forward"
  			targetGroupArn: "${resources.targetGroup.outputs.targetGroupArn}"
  		}]
  		tags: #WebTags
  	}
  }
}

Excerpted from examples/stacks/end-to-end.cue. Open the complete example for its variables and related resources.

Complete examples in the repository

Desired state

Configuration

The spec block accepts 7 fields. 5 are required by the schema; fields with defaults can be omitted.

accountOptional

Account.

string
String
regionOptional

Region.

string
String
listenerArnRequired

Listener ARN.

string
String
priorityRequired

Priority.

int & >=1 & <=50000
Integer
conditionsRequired

Conditions.

[...#RuleCondition] & [_, ...]
List
actionsRequired

Actions.

[...#RuleAction] & [_, ...]
List
tagsRequired

Tags.

[string]: string
Map

Observed values

Outputs

Praxis records these values after observation. A dependent resource can read one with ${resources.<name>.outputs.<field>}.

ruleArnString
priorityInteger

Read without ownership

Data-source lookup

A data block reads an existing ListenerRule and exposes its outputs without storing lifecycle state. The generic filter surface accepts id, name, and tag; supported combinations depend on the AWS identity used by this resource.

CUE data source
data: existing: {
  kind: "ListenerRule"
  region: "us-west-2"
  filter: {
    name: "replace-with-provider-name"
  }
}

Understand data sources and filters →

Adopt existing infrastructure

Import

Import persists Praxis state for an existing AWS resource. For this kind, supply: Provider identifier for the existing ListenerRule. The example starts in observed mode so Praxis reports drift without correcting it.

CLI
praxis import ListenerRule \
  --id <provider-identifier> \
  --region us-west-2 \
  --account production \
  --observe

Choose managed or observed ownership →

Canonical contract

Complete CUE schema

The field guide above is derived from this definition. The schema remains the source of truth for accepted values, defaults, validation constraints, and outputs in the current alpha revision.

Show the complete schema
schemas/aws/elb/listener_rule.cue
package elb

#ListenerRule: {
	apiVersion: "praxis.io/alpha"
	kind:       "ListenerRule"

	metadata: {
		name: string & =~"^[a-zA-Z0-9]([a-zA-Z0-9-]{0,30}[a-zA-Z0-9])?$"
		labels: [string]: string
	}

	spec: {
		account?:    string
		region?:     string
		listenerArn: string
		priority:    int & >=1 & <=50000
		conditions: [...#RuleCondition] & [_, ...]
		actions: [...#RuleAction] & [_, ...]
		tags: [string]: string
	}

	outputs?: {
		ruleArn:  string
		priority: int
	}
}

#RuleCondition: {
	field: "path-pattern" | "host-header" | "http-header" | "query-string" | "source-ip" | "http-request-method"
	values?: [...string]
	httpHeaderConfig?: {
		name: string
		values: [...string] & [_, ...]
	}
	queryStringConfig?: values: [...#QueryStringKV] & [_, ...]
}

#QueryStringKV: {
	key:   string
	value: string
}

#RuleAction: {
	type:            "forward" | "redirect" | "fixed-response"
	order?:          int & >=1
	targetGroupArn?: string
	forwardConfig?: {
		targetGroups: [...#WeightedTargetGroup] & [_, ...]
		stickiness?: {
			enabled:  bool | *false
			duration: int & >=1 & <=604800
		}
	}
	redirectConfig?: {
		protocol:   string
		host:       string
		port:       string
		path:       string
		query:      string
		statusCode: "HTTP_301" | "HTTP_302"
	}
	fixedResponseConfig?: {
		statusCode:  string
		contentType: string
		messageBody: string
	}
}

#WeightedTargetGroup: {
	targetGroupArn: string
	weight:         int & >=0 & <=999 | *1
}

View this schema on GitHub →