Search code examples
amazon-web-servicescloudaws-cliaws-application-load-balancer

AWS CLI ALB: Modify default action of http listener to redirect


I am trying to modify default action of a http listener in ALB to redirect using awscli. This is to redirect traffic on HTTP listener to HTTPS listener.

I am trying the below command but it fails. Can someone please help me with this. How can I add redirect config in command ?

AWSCLI documentation doesn't seem to be much helpful in this.

aws elbv2 modify-listener --listener-arn $LISTENER_ARN --default-actions Type=redirect,RedirectConfig={Protocol=HTTPS,Port=443,Host=#{host},Path=/#{path},Query=#{query},StatusCode=HTTP_301}

Error:

Error parsing parameter '--default-actions': Expected: ',', received: '}' for input: Type=redirect,RedirectConfig=Host=#{host}

Thanks


Solution

  • Redirect config should be like this

    aws elbv2 modify-listener --listener-arn <listener> --default-actions '[{"Type": "redirect", "RedirectConfig": {"Protocol": "HTTPS", "Port": "443", "Host": "#{host}", "Query": "#{query}", "Path": "/#{path}", "StatusCode": "HTTP_301"}}]'