Class: AWSCDK::ECS::CfnService::LoadBalancerProperty

Inherits:
Jsii::Struct
  • Object
show all
Defined in:
ecs/cfn_service.rb

Overview

The LoadBalancer property specifies details on a load balancer that is used with a service.

If the service is using the CODE_DEPLOY deployment controller, the service is required to use either an Application Load Balancer or Network Load Balancer. When you are creating an AWS CodeDeploy deployment group, you specify two target groups (referred to as a target_group_pair ). Each target group binds to a separate task set in the deployment. The load balancer can also have up to two listeners, a required listener for production traffic and an optional listener that allows you to test new revisions of the service before routing production traffic to it.

Services with tasks that use the awsvpc network mode (for example, those with the Fargate launch type) only support Application Load Balancers and Network Load Balancers. Classic Load Balancers are not supported. Also, when you create any target groups for these services, you must choose ip as the target type, not instance . Tasks that use the awsvpc network mode are associated with an elastic network interface, not an Amazon EC2 instance.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(advanced_configuration: nil, container_name: nil, container_port: nil, load_balancer_name: nil, target_group_arn: nil) ⇒ LoadBalancerProperty

Returns a new instance of LoadBalancerProperty.

Parameters:

  • advanced_configuration (AWSCDK::IResolvable, AWSCDK::ECS::CfnService::AdvancedConfigurationProperty, nil) (defaults to: nil)

    The advanced settings for the load balancer used in blue/green deployments.

  • container_name (String, nil) (defaults to: nil)

    The name of the container (as it appears in a container definition) to associate with the load balancer.

  • container_port (Numeric, nil) (defaults to: nil)

    The port on the container to associate with the load balancer.

  • load_balancer_name (String, nil) (defaults to: nil)

    The name of the load balancer to associate with the Amazon ECS service or task set.

  • target_group_arn (String, nil) (defaults to: nil)

    The full Amazon Resource Name (ARN) of the Elastic Load Balancing target group or groups associated with a service or task set.



1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
# File 'ecs/cfn_service.rb', line 1892

def initialize(advanced_configuration: nil, container_name: nil, container_port: nil, load_balancer_name: nil, target_group_arn: nil)
  @advanced_configuration = advanced_configuration.is_a?(Hash) ? ::AWSCDK::ECS::CfnService::AdvancedConfigurationProperty.new(**advanced_configuration.transform_keys(&:to_sym)) : advanced_configuration
  Jsii::Type.check_type(@advanced_configuration, JSON.parse(Base64.strict_decode64("eyJ1bmlvbiI6eyJ0eXBlcyI6W3siZnFuIjoiYXdzLWNkay1saWIuSVJlc29sdmFibGUifSx7ImZxbiI6ImF3cy1jZGstbGliLmF3c19lY3MuQ2ZuU2VydmljZS5BZHZhbmNlZENvbmZpZ3VyYXRpb25Qcm9wZXJ0eSJ9XX19")), "advancedConfiguration") unless @advanced_configuration.nil?
  @container_name = container_name
  Jsii::Type.check_type(@container_name, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "containerName") unless @container_name.nil?
  @container_port = container_port
  Jsii::Type.check_type(@container_port, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "containerPort") unless @container_port.nil?
  @load_balancer_name = load_balancer_name
  Jsii::Type.check_type(@load_balancer_name, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "loadBalancerName") unless @load_balancer_name.nil?
  @target_group_arn = target_group_arn
  Jsii::Type.check_type(@target_group_arn, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "targetGroupArn") unless @target_group_arn.nil?
end

Instance Attribute Details

#advanced_configurationAWSCDK::IResolvable, ... (readonly)

The advanced settings for the load balancer used in blue/green deployments.

Specify the alternate target group, listener rules, and IAM role required for traffic shifting during blue/green deployments.



1911
1912
1913
# File 'ecs/cfn_service.rb', line 1911

def advanced_configuration
  @advanced_configuration
end

#container_nameString? (readonly)

The name of the container (as it appears in a container definition) to associate with the load balancer.

You need to specify the container name when configuring the target group for an Amazon ECS load balancer.



1918
1919
1920
# File 'ecs/cfn_service.rb', line 1918

def container_name
  @container_name
end

#container_portNumeric? (readonly)

The port on the container to associate with the load balancer.

This port must correspond to a container_port in the task definition the tasks in the service are using. For tasks that use the EC2 launch type, the container instance they're launched on must allow ingress traffic on the host_port of the port mapping.



1925
1926
1927
# File 'ecs/cfn_service.rb', line 1925

def container_port
  @container_port
end

#load_balancer_nameString? (readonly)

The name of the load balancer to associate with the Amazon ECS service or task set.

If you are using an Application Load Balancer or a Network Load Balancer the load balancer name parameter should be omitted.



1932
1933
1934
# File 'ecs/cfn_service.rb', line 1932

def load_balancer_name
  @load_balancer_name
end

#target_group_arnString? (readonly)

The full Amazon Resource Name (ARN) of the Elastic Load Balancing target group or groups associated with a service or task set.

A target group ARN is only specified when using an Application Load Balancer or Network Load Balancer.

For services using the ECS deployment controller, you can specify one or multiple target groups. For more information, see Registering multiple target groups with a service in the Amazon Elastic Container Service Developer Guide .

For services using the CODE_DEPLOY deployment controller, you're required to define two target groups for the load balancer. For more information, see Blue/green deployment with CodeDeploy in the Amazon Elastic Container Service Developer Guide .

If your service's task definition uses the awsvpc network mode, you must choose ip as the target type, not instance . Do this when creating your target groups because tasks that use the awsvpc network mode are associated with an elastic network interface, not an Amazon EC2 instance. This network mode is required for the Fargate launch type.



1945
1946
1947
# File 'ecs/cfn_service.rb', line 1945

def target_group_arn
  @target_group_arn
end

Class Method Details

.jsii_propertiesObject



1947
1948
1949
1950
1951
1952
1953
1954
1955
# File 'ecs/cfn_service.rb', line 1947

def self.jsii_properties
  {
    :advanced_configuration => "advancedConfiguration",
    :container_name => "containerName",
    :container_port => "containerPort",
    :load_balancer_name => "loadBalancerName",
    :target_group_arn => "targetGroupArn",
  }
end

Instance Method Details

#to_jsiiObject



1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
# File 'ecs/cfn_service.rb', line 1957

def to_jsii
  result = {}
  result.merge!({
    "advancedConfiguration" => @advanced_configuration,
    "containerName" => @container_name,
    "containerPort" => @container_port,
    "loadBalancerName" => @load_balancer_name,
    "targetGroupArn" => @target_group_arn,
  })
  result.compact
end