Last active
January 28, 2020 16:20
-
-
Save ns-mkusper/2117f91153ef56994d009af8457e2b49 to your computer and use it in GitHub Desktop.
Add HTTP->HTTPS redirect for ALB's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for alb in $(aws elbv2 describe-load-balancers --query 'LoadBalancers[].LoadBalancerArn[]');do | |
DEFAULT_PORT=$(aws elbv2 describe-listeners --load-balancer-arn $alb --query 'Listeners[].{Port:Port}') | |
if [ "$DEFAULT_PORT" == "443" ];then | |
echo "ALB $alb is listening on port $DEFAULT_PORT" | |
echo "Adding listener on $alb to redirect $NEW_PORT to $DEFAULT_PORT" | |
aws elbv2 create-listener --load-balancer-arn $alb --protocol HTTP --port 80 --default-actions '[ | |
{ | |
"RedirectConfig": { | |
"Protocol": "HTTPS", | |
"Host": "#{host}", | |
"Query": "#{query}", | |
"Path": "/#{path}", | |
"Port": "443", | |
"StatusCode": "HTTP_301" | |
}, | |
"Type": "redirect", | |
"Order": 1 | |
} | |
]' | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment