'How to redirect port 80 to 443 in Network Load Balancer

farwardtotargetgroup:      
  Type: AWS::ElasticLoadBalancingV2::Listener
  Properties: 
    Certificates: 
     - CertificateArn: !Ref cert
    DefaultActions: 
      - TargetGroupArn: !Ref target-group
        Type: forward
    LoadBalancerArn: !Ref nlb
    Port: 443 
    Protocol: TLS
redirectto443:      
  Type: AWS::ElasticLoadBalancingV2::Listener
  Properties: 
    DefaultActions: 
      - RedirectConfig: 
          Port: 443
          StatusCode: HTTP_301 
        Type: redirect 
    LoadBalancerArn: !Ref nlb
    Port: 80 
    Protocol: TLS

When I execute template I got:

The action type 'redirect' is not valid with network load balancer (Service: AmazonElasticLoadBalancingV2; Status Code: 400; Error Code: InvalidLoadBalancerAction;



Solution 1:[1]

Redirect rules are only supported for Application Load Balancers, not a network load balancer.

If you can use an application load balancer for your application then you will be able to make use of it.

From documentation

[Application Load Balancer] Information for creating a redirect action. Specify only when Type is redirect.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1