Skip to main content

Listener Rule

Manage an ELB Listener Rule.

Example#

HTTP to HTTPS rule#

Provide a rule to redirect HTTP traffic to HTTPS.

const ruleHttp2Https = await provider.makeRule({
name: "rule-httt2https",
dependencies: {
listener: listenerHttp,
},
properties: () => ({
Actions: [
{
Type: "redirect",
Order: 1,
RedirectConfig: {
Protocol: "HTTPS",
Port: "443",
Host: "#{host}",
Path: "/#{path}",
Query: "#{query}",
StatusCode: "HTTP_301",
},
},
],
Conditions: [
{
Field: "path-pattern",
Values: ["/*"],
},
],
Priority: 1,
}),
});

Forward to target group based on a path pattern#

Forward traffic matching /api/ to the target group running the REST server.

const ruleHttps = await provider.makeRule({
name: "rule-httt2https",
dependencies: {
listener: listeners.https,
targetGroup: targetGroups.rest,
},
properties: ({ dependencies: { targetGroup } }) => ({
Actions: [
{
TargetGroupArn: targetGroup.live?.TargetGroupArn,
Type: "forward",
},
],
Conditions: [
{
Field: "path-pattern",
Values: ["/api/*"],
},
],
Priority: 10,
}),
});

Properties#

Source Code#

Dependencies#

List#

gc l -t ListenerRule