From 82ad66256ae6e304c08f0b8553273cc78f1d6714 Mon Sep 17 00:00:00 2001 From: Hugo Lopes Tavares Date: Fri, 27 Oct 2017 15:01:17 -0400 Subject: [PATCH] Add default name to TargetGroup (cloudformation) --- moto/elbv2/models.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/moto/elbv2/models.py b/moto/elbv2/models.py index 4fd4147f..4e3c928a 100644 --- a/moto/elbv2/models.py +++ b/moto/elbv2/models.py @@ -113,7 +113,10 @@ class FakeTargetGroup(BaseModel): elbv2_backend = elbv2_backends[region_name] - name = properties.get('Name') + # per cloudformation docs: + # The target group name should be shorter than 22 characters because + # AWS CloudFormation uses the target group name to create the name of the load balancer. + name = properties.get('Name', resource_name[:22]) vpc_id = properties.get("VpcId") protocol = properties.get('Protocol') port = properties.get("Port") @@ -364,7 +367,7 @@ class ELBv2Backend(BaseBackend): def create_target_group(self, name, **kwargs): if len(name) > 32: raise InvalidTargetGroupNameError( - "Target group name '%s' cannot be longer than '32' characters" % name + "Target group name '%s' cannot be longer than '22' characters" % name ) if not re.match('^[a-zA-Z0-9\-]+$', name): raise InvalidTargetGroupNameError(