2019/02/28

AWS ALB redirect HTTP to HTTPS configuration in command line

CURRENT CONFIGURATION: AWS Application Load Balancer created by Elastic Beanstalk
OBJECTIVE: redirect HTTP to HTTPS on port 80 by default by command line
ISSUE: lack of clear example.
SOLUTION:
aws elbv2 modify-listener --listener-arn <$ebs_alb_listener_http> --default-actions '[{"Type": "redirect", "RedirectConfig": {"Protocol": "HTTPS", "Port": "443", "Host": "#{host}", "Query": "#{query}", "Path": "/#{path}", "StatusCode": "HTTP_301"}}]' --region <$my_aws_region>

LINKS: Elastic Load Balancing Announces Support for Redirects and Fixed Responses for Application Load Balancer
AWS cli elbv2 modify-listener