【问题标题】:Add Target Group to application listener (AWS CDK PYTHON)将目标组添加到应用程序侦听器 (AWS CDK PYTHON)
【发布时间】:2021-01-29 01:20:30
【问题描述】:

我一直在尝试运行此代码但未成功,我正在使用 python 和 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)

我得到的错误如下:

init 中的文件“/home/user/workspace/test/cdk/pytest/pytest/pytest_stack.py”,第 33 行 httpsListener.add_target_groups('TargetGroups', applicationTargetGroup) TypeError: add_target_groups() 接受 2 个位置参数,但给出了 3 个

我不明白我做错了什么,因为文档说明没问题:

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

AWS DOCS

谢谢

【问题讨论】:

  • 函数签名中* 之后的参数仅通过关键字传递。有关更多说明,请参阅this answer,或PEP-3102
  • 你是说我应该这样做:httpsListener.add_target_groups('TargetGroups', target_groups=applicationTargetGroup, host_header='host.domain.com', priority=107)
  • 是的,完全正确

标签: python amazon-web-services aws-cdk


【解决方案1】:

add_target_groups 的文档告诉 applicationTargetGroup 传递了一个 key word argument 和一个 list

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

【讨论】:

  • 我遇到了一个新错误,但我想是无关的。谢谢。不接受作为答案。 C.Nivs 对不起,我不能接受 cmets 作为答案 :)
  • @ChopLabalagun 没问题。请随时就新问题提出新问题。
猜你喜欢
  • 2020-11-02
  • 2021-05-02
  • 2021-02-17
  • 2021-06-25
  • 2014-12-29
  • 2014-08-26
  • 1970-01-01
  • 2013-03-09
  • 2018-10-13
相关资源
最近更新 更多