ApplicationListenerRule

class aws_cdk.aws_elasticloadbalancingv2.ApplicationListenerRule(scope, id, *, listener, priority, action=None, conditions=None, target_groups=None)

Bases: Construct

Define a new listener rule.

ExampleMetadata:

infused

Example:

import aws_cdk.aws_lambda as lambda_

# cluster: ecs.Cluster
# task_definition: ecs.TaskDefinition
# lambda_hook: lambda.Function
# blue_target_group: elbv2.ApplicationTargetGroup
# green_target_group: elbv2.ApplicationTargetGroup
# prod_listener_rule: elbv2.ApplicationListenerRule


service = ecs.FargateService(self, "Service",
    cluster=cluster,
    task_definition=task_definition,
    deployment_strategy=ecs.DeploymentStrategy.BLUE_GREEN
)

service.add_lifecycle_hook(ecs.DeploymentLifecycleLambdaTarget(lambda_hook, "PreScaleHook",
    lifecycle_stages=[ecs.DeploymentLifecycleStage.PRE_SCALE_UP]
))

target = service.load_balancer_target(
    container_name="nginx",
    container_port=80,
    protocol=ecs.Protocol.TCP,
    alternate_target=ecs.AlternateTarget("AlternateTarget",
        alternate_target_group=green_target_group,
        production_listener=ecs.ListenerRuleConfiguration.application_listener_rule(prod_listener_rule)
    )
)

target.attach_to_application_target_group(blue_target_group)
Parameters:
  • scope (Construct)

  • id (str)

  • listener (IApplicationListener) – The listener to attach the rule to.

  • priority (Union[int, float]) – Priority of the rule. The rule with the lowest priority will be used for every request. Priorities must be unique.

  • action (Optional[ListenerAction]) – Action to perform when requests are received. Only one of action, fixedResponse, redirectResponse or targetGroups can be specified. Default: - No action

  • conditions (Optional[Sequence[ListenerCondition]]) – Rule applies if matches the conditions. Default: - No conditions.

  • target_groups (Optional[Sequence[IApplicationTargetGroup]]) – Target groups to forward requests to. Only one of action, fixedResponse, redirectResponse or targetGroups can be specified. Implies a forward action. Default: - No target groups.

Methods

add_condition(condition)

Add a non-standard condition to this rule.

Parameters:

condition (ListenerCondition)

Return type:

None

configure_action(action)

Configure the action to perform for this rule.

Parameters:

action (ListenerAction)

Return type:

None

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

listener_rule_arn

The ARN of this rule.

node

The tree node.

Static Methods

classmethod is_construct(x)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters:

x (Any) – Any object.

Return type:

bool

Returns:

true if x is an object created from a class which extends Construct.