title: How to correctly code AWS ALB redirection in CDK (python)
body: <p>Learning AWS CDK (coming from terraform). I'm currently struggling, how to write a piece of code with will allow me to create redirection as in below screenshot:
  <a href="https://i.stack.imgur.com/TeHcK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TeHcK.png" alt="enter image description here" /></a></p>
  <p>Code so far which I have:</p>
  <pre><code>class LoadBalancer(core.Construct):
  
  def __init__(self, scope: core.Construct, construct_id: str, props):
      super().__init__(scope, construct_id)
      self.props = props
  
  def load_balancer(self, security_group, fargate_service, arn_certificates_list):
      load_balancer = alb.ApplicationLoadBalancer(
          self,
          &quot;TestFargateALB&quot;,
          vpc=self.props[&quot;vpc&quot;],
          deletion_protection=True if self.props[&quot;environment&quot;].lower() == &quot;prod&quot; else False,
          http2_enabled=True,
          internet_facing=True,
          security_group=security_group
      )
  
      load_balancer.set_attribute(key=&quot;routing.http.drop_invalid_header_fields.enabled&quot;, value=&quot;true&quot;)
  
      http_load_balancer_listener = load_balancer.add_listener(
          'http_listener', port=80, open=False
      )
  
      https_load_balancer_listener = load_balancer.add_listener(
          &quot;https_listener&quot;, port=443, open=False, certificate_arns=arn_certificates_list
      )
  
      https_target_group = https_load_balancer_listener.add_targets(
          'ecs_target_group',
          targets=[fargate_service],
          port=80,
          protocol=alb.ApplicationProtocol.HTTP,
          deregistration_delay=core.Duration.seconds(amount=10)
      )
  
      https_target_group.configure_health_check(
          healthy_http_codes=&quot;200,301,302&quot;,
          healthy_threshold_count=3,
          interval=core.Duration.seconds(10),
          timeout=core.Duration.seconds(5),
          unhealthy_threshold_count=5,
          path=&quot;/&quot;
      )
  
      http_load_balancer_listener.add_action(
          'DefaultAction',
          action=alb.ListenerAction(action_json=alb.CfnListener.ActionProperty(
              type=&quot;redirect&quot;,
              redirect_config=alb.CfnListener.RedirectConfigProperty(
                  status_code=&quot;HTTP_301&quot;,
                  host=&quot;#{host}&quot;,
                  protocol=&quot;HTTPS&quot;,
                  port=&quot;443&quot;,
                  path=&quot;#{path}&quot;,
                  query=&quot;#{query}&quot;
              )
          ))
      )
  
      alb.ApplicationListenerRule(self, &quot;HttpsRule&quot;,
                                  listener=https_load_balancer_listener,
                                  priority=1,
                                  path_pattern=&quot;/&quot;,
                                  target_groups=[https_target_group]
                                  )
  
      return load_balancer
  </code></pre>
  <p>Error which CDK is throwing during deployment:</p>
  <p><code>5:04:16 PM | CREATE_FAILED        | AWS::ElasticLoadBalancingV2::Listener     | TestALBTestFargate...tplistener3A9BAD2E The Path parameter must be a valid path, should start with a '/', and may contain up to one of each of these placeholders: '#{path}', '#{host}', '#{port}'. (Service: ElasticLoadBalancingV2, Status Code: 400, Request ID: 9cc3b04c-0787-4455-a7ee-2a1b3e9a30b3, Exten ded Request ID: null)</code></p>
  <p>Can someone could help me out on how to write this piece correctly?</p>