Skip to main content

Rule

Manage an ELB Listener Rule.

Example

HTTP to HTTPS rule

Provide a rule to redirect HTTP traffic to HTTPS.

exports.createResources = () => [
{
type: "Rule",
group: "ElasticLoadBalancingV2",
properties: ({}) => ({
Priority: "1",
Conditions: [
{
Field: "path-pattern",
Values: ["/*"],
},
],
Actions: [
{
Type: "redirect",
Order: 1,
RedirectConfig: {
Protocol: "HTTPS",
Port: "443",
Host: "#{host}",
Path: "/#{path}",
Query: "#{query}",
StatusCode: "HTTP_301",
},
},
],
}),
dependencies: () => ({
listener: "listener::load-balancer::HTTP::80",
}),
},
];

Forward to target group based on a path pattern

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

exports.createResources = () => [
{
type: "Rule",
group: "ElasticLoadBalancingV2",
properties: ({}) => ({
Priority: "1",
Conditions: [
{
Field: "path-pattern",
Values: ["/api/*"],
},
],
}),
dependencies: () => ({
listener: "listener::load-balancer::HTTPS::443",
targetGroup: "target-group-rest",
}),
},
];

Properties

Source Code

Dependencies

List

gc l -t ElasticLoadBalancingV2::Rule
Listing resources on 1 provider: aws
✓ aws
✓ Initialising
✓ Listing 9/9
┌─────────────────────────────────────────────────────────────────────────────┐
│ 5 ElasticLoadBalancingV2::Rule from aws │
├─────────────────────────────────────────────────────────────────────────────┤
│ name: rule-default-listener::load-balancer::HTTP::80::default │
│ managedByUs: NO │
│ live: │
│ RuleArn: arn:aws:elasticloadbalancing:us-east-1:840541460064:listener-ru… │
│ Priority: default │
│ Conditions: [] │
│ Actions: │
│ - Type: forward │
│ TargetGroupArn: arn:aws:elasticloadbalancing:us-east-1:840541460064:… │
│ ForwardConfig: │
│ TargetGroups: │
│ - TargetGroupArn: arn:aws:elasticloadbalancing:us-east-1:8405414… │
│ Weight: 1 │
│ TargetGroupStickinessConfig: │
│ Enabled: false │
│ IsDefault: true │
│ ListenerArn: arn:aws:elasticloadbalancing:us-east-1:840541460064:listene… │
│ Tags: [] │
│ │
├─────────────────────────────────────────────────────────────────────────────┤
│ name: rule-default-listener::load-balancer::HTTPS::443::default │
│ managedByUs: NO │
│ live: │
│ RuleArn: arn:aws:elasticloadbalancing:us-east-1:840541460064:listener-ru… │
│ Priority: default │
│ Conditions: [] │
│ Actions: │
│ - Type: forward │
│ TargetGroupArn: arn:aws:elasticloadbalancing:us-east-1:840541460064:… │
│ ForwardConfig: │
│ TargetGroups: │
│ - TargetGroupArn: arn:aws:elasticloadbalancing:us-east-1:8405414… │
│ Weight: 1 │
│ TargetGroupStickinessConfig: │
│ Enabled: false │
│ IsDefault: true │
│ ListenerArn: arn:aws:elasticloadbalancing:us-east-1:840541460064:listene… │
│ Tags: [] │
│ │
├─────────────────────────────────────────────────────────────────────────────┤
│ name: rule::listener::load-balancer::HTTP::80::1 │
│ managedByUs: Yes │
│ live: │
│ RuleArn: arn:aws:elasticloadbalancing:us-east-1:840541460064:listener-ru… │
│ Priority: 1 │
│ Conditions: │
│ - Field: path-pattern │
│ Values: │
│ - "/*" │
│ PathPatternConfig: │
│ Values: │
│ - "/*" │
│ Actions: │
│ - Type: redirect │
│ Order: 1 │
│ RedirectConfig: │
│ Protocol: HTTPS │
│ Port: 443 │
│ Host: #{host} │
│ Path: /#{path} │
│ Query: #{query} │
│ StatusCode: HTTP_301 │
│ IsDefault: false │
│ ListenerArn: arn:aws:elasticloadbalancing:us-east-1:840541460064:listene… │
│ Tags: │
│ - Key: gc-created-by-provider │
│ Value: aws │
│ - Key: gc-managed-by │
│ Value: grucloud │
│ - Key: gc-project-name │
│ Value: @grucloud/example-aws-elbv2-loadbalancer │
│ - Key: gc-stage │
│ Value: dev │
│ - Key: Name │
│ Value: rule::listener::load-balancer::HTTP::80::1 │
│ │
├─────────────────────────────────────────────────────────────────────────────┤
│ name: rule::listener::load-balancer::HTTPS::443::1 │
│ managedByUs: Yes │
│ live: │
│ RuleArn: arn:aws:elasticloadbalancing:us-east-1:840541460064:listener-ru… │
│ Priority: 1 │
│ Conditions: │
│ - Field: path-pattern │
│ Values: │
│ - "/api/*" │
│ PathPatternConfig: │
│ Values: │
│ - "/api/*" │
│ Actions: │
│ - Type: forward │
│ TargetGroupArn: arn:aws:elasticloadbalancing:us-east-1:840541460064:… │
│ Order: 1 │
│ ForwardConfig: │
│ TargetGroups: │
│ - TargetGroupArn: arn:aws:elasticloadbalancing:us-east-1:8405414… │
│ Weight: 1 │
│ TargetGroupStickinessConfig: │
│ Enabled: false │
│ IsDefault: false │
│ ListenerArn: arn:aws:elasticloadbalancing:us-east-1:840541460064:listene… │
│ Tags: │
│ - Key: gc-created-by-provider │
│ Value: aws │
│ - Key: gc-managed-by │
│ Value: grucloud │
│ - Key: gc-project-name │
│ Value: @grucloud/example-aws-elbv2-loadbalancer │
│ - Key: gc-stage │
│ Value: dev │
│ - Key: Name │
│ Value: rule::listener::load-balancer::HTTPS::443::1 │
│ │
├─────────────────────────────────────────────────────────────────────────────┤
│ name: rule::listener::load-balancer::HTTPS::443::2 │
│ managedByUs: Yes │
│ live: │
│ RuleArn: arn:aws:elasticloadbalancing:us-east-1:840541460064:listener-ru… │
│ Priority: 2 │
│ Conditions: │
│ - Field: path-pattern │
│ Values: │
│ - "/*" │
│ PathPatternConfig: │
│ Values: │
│ - "/*" │
│ Actions: │
│ - Type: forward │
│ TargetGroupArn: arn:aws:elasticloadbalancing:us-east-1:840541460064:… │
│ Order: 1 │
│ ForwardConfig: │
│ TargetGroups: │
│ - TargetGroupArn: arn:aws:elasticloadbalancing:us-east-1:8405414… │
│ Weight: 1 │
│ TargetGroupStickinessConfig: │
│ Enabled: false │
│ IsDefault: false │
│ ListenerArn: arn:aws:elasticloadbalancing:us-east-1:840541460064:listene… │
│ Tags: │
│ - Key: gc-created-by-provider │
│ Value: aws │
│ - Key: gc-managed-by │
│ Value: grucloud │
│ - Key: gc-project-name │
│ Value: @grucloud/example-aws-elbv2-loadbalancer │
│ - Key: gc-stage │
│ Value: dev │
│ - Key: Name │
│ Value: rule::listener::load-balancer::HTTPS::443::2 │
│ │
└─────────────────────────────────────────────────────────────────────────────┘


List Summary:
Provider: aws
┌────────────────────────────────────────────────────────────────────────────┐
│ aws │
├─────────────┬──────────────────────────────────────────────────────────────┤
│ ElasticLoadBalancingV2::Rule │ rule-default-listener::load-balancer::HTTP::80::default │
│ │ rule-default-listener::load-balancer::HTTPS::443::default │
│ │ rule::listener::load-balancer::HTTP::80::1 │
│ │ rule::listener::load-balancer::HTTPS::443::1 │
│ │ rule::listener::load-balancer::HTTPS::443::2 │
└─────────────┴──────────────────────────────────────────────────────────────┘
5 resources, 1 type, 1 provider
Command "gc l -t ElasticLoadBalancingV2::Rule" executed in 10s