@@ -158,7 +158,9 @@ def handle_same_task_services_dependencies(
158158 service_config .family_dependents .append (
159159 {
160160 "ContainerName" : dependency ,
161- "Condition" : containers_config [dependency ]["config" ].container_start_condition
161+ "Condition" : containers_config [dependency ][
162+ "config"
163+ ].container_start_condition
162164 if not containers_config [dependency ]["config" ].healthcheck
163165 else "HEALTHY" ,
164166 }
@@ -566,9 +568,17 @@ def add_public_ips(self, azs):
566568 :rtype: list
567569 """
568570 for az in azs :
571+ if isinstance (az , dict ) and keyisset ("ZoneName" , az ):
572+ az_name = NONALPHANUM .sub (
573+ "" , az ["ZoneName" ].title ().replace ("-" , "" ).strip ()
574+ )
575+ elif isinstance (az , str ):
576+ az_name = NONALPHANUM .sub ("" , az )
577+ else :
578+ raise TypeError ("az is neither a dict or a str. Got" , type (az ))
569579 self .eips .append (
570580 EIP (
571- f"EipPublicNlb{ az . replace ( '-' , '' ). strip () } { self .service_name } " ,
581+ f"EipPublicNlb{ az_name } { self .service_name } " ,
572582 template = self .template ,
573583 Domain = "vpc" ,
574584 )
@@ -711,15 +721,9 @@ def add_load_balancer(self, settings):
711721 Key = "load_balancing.cross_zone.enabled" , Value = "true"
712722 )
713723 ]
714- if self .config .lb_type == "network"
715- else no_value ,
716- SecurityGroups = lb_sg ,
717- SubnetMappings = public_mapping
718- if self .config .is_public and self .config .use_nlb ()
724+ if self .config .use_nlb ()
719725 else no_value ,
720- Subnets = Ref (PUBLIC_SUBNETS )
721- if self .config .is_public and self .config .use_alb ()
722- else Ref (vpc_params .APP_SUBNETS ),
726+ SecurityGroups = lb_sg if self .config .use_alb () else no_value ,
723727 Type = self .config .lb_type ,
724728 Tags = Tags (
725729 {
@@ -729,6 +733,13 @@ def add_load_balancer(self, settings):
729733 }
730734 ),
731735 )
736+ if self .config .is_public and self .config .use_alb ():
737+ setattr (loadbalancer , "Subnets" , Ref (PUBLIC_SUBNETS ))
738+ elif self .config .is_public and self .config .use_nlb ():
739+ setattr (loadbalancer , "SubnetMappings" , public_mapping )
740+ setattr (loadbalancer , "Subnets" , Ref (AWS_NO_VALUE ))
741+ elif not self .config .is_public :
742+ setattr (loadbalancer , "Subnets" , Ref (vpc_params .APP_SUBNETS ))
732743 if self .config .is_public :
733744 sd_service = SdService (
734745 f"{ self .resource_name } PublicDiscoveryService" ,
@@ -782,7 +793,7 @@ def add_service_load_balancer(self, settings):
782793 EcsLoadBalancer (
783794 TargetGroupArn = Ref (tgt ),
784795 ContainerPort = tgt .Port ,
785- ContainerName = self .config .lb_service_name ,
796+ ContainerName = NONALPHANUM . sub ( "" , self .config .lb_service_name ) ,
786797 )
787798 )
788799 return service_lbs , depends_on
0 commit comments