1

I have been trying to run this code unsuccessfully, i am using python and the AWS CDK:

        applicationTargetGroup = elbv2.ApplicationTargetGroup(self, 'ApplicationTargetGroup', 
                            target_type=elbv2.TargetType.IP,
                            target_group_name='stg-test',
                            protocol=elbv2.ApplicationProtocol.HTTP,
                            port=8080,
                            vpc=vpc,
                            health_check=elbv2.HealthCheck(path='/images/favicon.ico')
                            )

    httpsListener.add_target_groups('TargetGroups', 
                            applicationTargetGroup, 
                            host_header='host.domain.com', 
                            priority=107)

The error I get is the following:

File "/home/user/workspace/test/cdk/pytest/pytest/pytest_stack.py", line 33, in init httpsListener.add_target_groups('TargetGroups', applicationTargetGroup) TypeError: add_target_groups() takes 2 positional arguments but 3 were given

I dont understand what I am doing wrong as the documentation states is ok:

add_target_groups(id, *, target_groups, conditions=None, host_header=None, path_pattern=None, path_patterns=None, priority=None)

AWS DOCS

thanks

3
  • Arguments after a * in the function signature are passed by keyword only. See this answer for more clarification, or also PEP-3102 Commented Jan 29, 2021 at 1:24
  • so are you saying i should do it like this: httpsListener.add_target_groups('TargetGroups', target_groups=applicationTargetGroup, host_header='host.domain.com', priority=107) Commented Jan 29, 2021 at 1:31
  • Yes, that's exactly right Commented Jan 29, 2021 at 1:31

1 Answer 1

1

The docs for add_target_groups it tell that applicationTargetGroup is passed a key word argument and a list:

    httpsListener.add_target_groups(
                  'TargetGroups', 
                  target_groups=[applicationTargetGroup],  
                  host_header='host.domain.com', 
                  priority=107)
Sign up to request clarification or add additional context in comments.

2 Comments

i got a new error but i guess is unrelated. Thanks. ill accept as answer. C.Nivs sorry i cant accept comments as answers :)
@ChopLabalagun No problem. Please feel free to make new question regarding the new issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.