ApplicationListenerRule
Define a new listener rule.
Example
declare const cluster: ecs.Cluster;
declare const taskDefinition: ecs.TaskDefinition;
declare const blueTargetGroup: elbv2.ApplicationTargetGroup;
declare const greenTargetGroup: elbv2.ApplicationTargetGroup;
declare const prodListenerRule: elbv2.ApplicationListenerRule;
const service = new ecs.FargateService(this, 'Service', {
cluster,
taskDefinition,
deploymentStrategy: ecs.DeploymentStrategy.LINEAR,
linearConfiguration: {
stepPercent: 10.0,
stepBakeTime: Duration.minutes(5),
},
});
const target = service.loadBalancerTarget({
containerName: 'web',
containerPort: 80,
alternateTarget: new ecs.AlternateTarget('AlternateTarget', {
alternateTargetGroup: greenTargetGroup,
productionListener: ecs.ListenerRuleConfiguration.applicationListenerRule(prodListenerRule),
}),
});
target.attachToApplicationTargetGroup(blueTargetGroup);
# cluster: ecs.Cluster
# task_definition: ecs.TaskDefinition
# 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.LINEAR,
linear_configuration=ecs.TrafficShiftConfig(
step_percent=10,
step_bake_time=Duration.minutes(5)
)
)
target = service.load_balancer_target(
container_name="web",
container_port=80,
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)
Cluster cluster;
TaskDefinition taskDefinition;
ApplicationTargetGroup blueTargetGroup;
ApplicationTargetGroup greenTargetGroup;
ApplicationListenerRule prodListenerRule;
FargateService service = FargateService.Builder.create(this, "Service")
.cluster(cluster)
.taskDefinition(taskDefinition)
.deploymentStrategy(DeploymentStrategy.LINEAR)
.linearConfiguration(TrafficShiftConfig.builder()
.stepPercent(10)
.stepBakeTime(Duration.minutes(5))
.build())
.build();
IEcsLoadBalancerTarget target = service.loadBalancerTarget(LoadBalancerTargetOptions.builder()
.containerName("web")
.containerPort(80)
.alternateTarget(AlternateTarget.Builder.create("AlternateTarget")
.alternateTargetGroup(greenTargetGroup)
.productionListener(ListenerRuleConfiguration.applicationListenerRule(prodListenerRule))
.build())
.build());
target.attachToApplicationTargetGroup(blueTargetGroup);
// Install: dotnet add package Amazon.CDK.Lib
Cluster cluster;
TaskDefinition taskDefinition;
ApplicationTargetGroup blueTargetGroup;
ApplicationTargetGroup greenTargetGroup;
ApplicationListenerRule prodListenerRule;
var service = new FargateService(this, "Service", new FargateServiceProps {
Cluster = cluster,
TaskDefinition = taskDefinition,
DeploymentStrategy = DeploymentStrategy.LINEAR,
LinearConfiguration = new TrafficShiftConfig {
StepPercent = 10,
StepBakeTime = Duration.Minutes(5)
}
});
var target = service.LoadBalancerTarget(new LoadBalancerTargetOptions {
ContainerName = "web",
ContainerPort = 80,
AlternateTarget = new AlternateTarget("AlternateTarget", new AlternateTargetProps {
AlternateTargetGroup = greenTargetGroup,
ProductionListener = ListenerRuleConfiguration.ApplicationListenerRule(prodListenerRule)
})
});
target.AttachToApplicationTargetGroup(blueTargetGroup);
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var cluster Cluster
var taskDefinition TaskDefinition
var blueTargetGroup ApplicationTargetGroup
var greenTargetGroup ApplicationTargetGroup
var prodListenerRule ApplicationListenerRule
service := ecs.NewFargateService(this, jsii.String("Service"), &FargateServiceProps{
Cluster: Cluster,
TaskDefinition: TaskDefinition,
DeploymentStrategy: ecs.DeploymentStrategy_LINEAR,
LinearConfiguration: &TrafficShiftConfig{
StepPercent: jsii.Number(10),
StepBakeTime: awscdk.Duration_Minutes(jsii.Number(5)),
},
})
target := service.LoadBalancerTarget(&LoadBalancerTargetOptions{
ContainerName: jsii.String("web"),
ContainerPort: jsii.Number(80),
AlternateTarget: ecs.NewAlternateTarget(jsii.String("AlternateTarget"), &AlternateTargetProps{
AlternateTargetGroup: greenTargetGroup,
ProductionListener: ecs.ListenerRuleConfiguration_ApplicationListenerRule(prodListenerRule),
}),
})
target.AttachToApplicationTargetGroup(blueTargetGroup)
Initializer
new ApplicationListenerRule(scope: Construct, id: string, props: ApplicationListenerRuleProps)
ApplicationListenerRule(scope: Construct, id: str, props: ApplicationListenerRuleProps)
new ApplicationListenerRule(Construct scope, String id, ApplicationListenerRuleProps props)
new ApplicationListenerRule(Construct scope, string id, ApplicationListenerRuleProps props)
NewApplicationListenerRule(Scope Construct, Id *string, Props ApplicationListenerRuleProps)
Construct Props
actionoptionalListenerActionactionoptionalListenerActionactionoptionalListenerActionActionoptionalListenerActionActionoptionalListenerAction#Default: No action
Only one of action, fixedResponse, redirectResponse or targetGroups can be specified.
conditionsoptionalListenerCondition[]conditionsoptionaltyping.List[ListenerCondition]conditionsoptionalList<ListenerCondition>ConditionsoptionalListenerCondition[]Conditionsoptional*[]ListenerCondition#Default: No conditions.
listenerIApplicationListenerlistenerIApplicationListenerlistenerIApplicationListenerListenerIApplicationListenerListenerIApplicationListenerrequired#The rule with the lowest priority will be used for every request.
Priorities must be unique.
targetGroupsoptionalIApplicationTargetGroup[]target_groupsoptionaltyping.List[IApplicationTargetGroup]targetGroupsoptionalList<IApplicationTargetGroup>TargetGroupsoptionalIApplicationTargetGroup[]TargetGroupsoptional*[]IApplicationTargetGroup#Default: No target groups.
Only one of action, fixedResponse, redirectResponse or targetGroups can be specified.
Implies a forward action.
Properties
Methods
addCondition(condition: ListenerCondition): voiddef add_condition(self, condition: ListenerCondition) -> Nonepublic void addCondition(ListenerCondition condition)public void AddCondition(ListenerCondition condition)func AddCondition(Condition ListenerCondition)#configureAction(action: ListenerAction): voiddef configure_action(self, action: ListenerAction) -> Nonepublic void configureAction(ListenerAction action)public void ConfigureAction(ListenerAction action)func ConfigureAction(Action ListenerAction)#isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#notes · 1 parameter · returns
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
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.
1 parameter · returns
Parameters
mixinsmixinsmixinsmixinsMixins— The mixins to apply.
Returns: This construct for chaining