copilot-cli icon indicating copy to clipboard operation
copilot-cli copied to clipboard

feature request: ALB supports Host Header

Open snowsky opened this issue 4 years ago • 13 comments

Copilot only supports "Path Pattern" now. We got a requirement to add a host header to ALB rule. Can the cloudformation resource codes be customized to do do?

snowsky avatar Oct 16 '20 02:10 snowsky

Hi! Thank you so much for reaching out :D

So host headers work best if your ALB has a custom DNS name. If you configure your app with a DNS name - then Copilot will switch to using host based routing.

Your endpoints will go from: http://alb-generated-url.elb.us-east-1.amazonaws.com/service-name to https://service-name.env-name.app-name.domain (we'll also generate an ACM cert for you)

Which uses host header routing.

We also have some plans to extend exactly how that routing works: #1188

Hope that helps!

kohidave avatar Oct 16 '20 02:10 kohidave

Thanks @kohidave for the prompt response and sorry for my late follow-up 👍

A quick question, how could I configure to add a header in routing rules?

snowsky avatar Oct 24 '20 23:10 snowsky

Hello @snowsky. Sorry for the late reply. For now within Copilot you can't add a header to the routing rules. However, you might find it helpful to use the ec2 console to manually add a header routing rule to the ALB listener.

iamhopaul123 avatar Feb 17 '21 08:02 iamhopaul123

Thanks @iamhopaul123 for the update. Is there any plan to add this feature?

snowsky avatar Feb 17 '21 16:02 snowsky

Can I ask why you want to add a host header to the rule? If it is because you want a custom domain name, then yes we plan to enhance our current default domain name. We might allow users to give aliases to the default domain or give custom domain name.

iamhopaul123 avatar Feb 17 '21 18:02 iamhopaul123

yes, got the same thought to have a custom domain name.

snowsky avatar Feb 17 '21 18:02 snowsky

Is this still the case? I wish to add header based listener rule to route traffic to a dedicated service/task... any clue, guys?

imaginarynik avatar Sep 26 '23 14:09 imaginarynik

@imaginarynik Hello 👋🏼 I will respond in this issue as this one seems more similar to your use case. Related: https://github.com/aws/copilot-cli/issues/2817.

If you simply want the traffic to be routed to, say,the service "web", then you can use the alias field.

Copilot will automatically generate a template with the desired host-header configuration to achieve your goal.

Lou1415926 avatar Sep 26 '23 17:09 Lou1415926

@Lou1415926 thank you for responding. I appreciate it. The config I want is that: all the traffic to my ALB goes through the regular listener rule to say, XYZ tasks. Now, I want that if the traffic happens to contain "crazy=1" header (not the host-header, I think, but just the regular HTTP header), then it should be routed to a different set of tasks (which are similar to other tasks, but dedicated to handle this crazy traffic). This seems a bit complicated to do with Copilot.

imaginarynik avatar Sep 27 '23 08:09 imaginarynik

@bvtujo Would you be able to help add custom-headers to this? I would really appreciate it ^_^

imaginarynik avatar Sep 27 '23 10:09 imaginarynik

@imaginarynik In general, you can use yaml patch to do this. For example, you could have ⬇️

- op: add
  path: Resources/HTTPListenerRuleByHttpHeader
  value: 
      Metadata: 'aws:copilot:description': 'An HTTP listener rule for path `/` that forwards HTTP traffic to your tasks'
      Type: AWS::ElasticLoadBalancingV2::ListenerRule
      Properties:
        Actions:
          - TargetGroupArn:# The target group for XYZ 
          Type: forward
        Conditions:
          - Field: 'http-header'
            HttpHeaderConfig: #... your config
      ListenerArn: !GetAtt EnvControllerAction.HTTPListenerArn
      Priority: !GetAtt HTTPRulePriorityAction.Priority

Lou1415926 avatar Sep 29 '23 19:09 Lou1415926

There are quite a few situations where we want to use ALB host headers, such as when replacing an existing system. (Not all of them are new systems.) If this is not feasible, you need to build something that stands ALB separately, either in the AWS console or terraform, etc., which is a very tedious job.

sasaki-kouhei avatar Dec 04 '23 08:12 sasaki-kouhei

@sasaki-kouhei love the input - would setting custom domain http.alias field help you in your case? Or can you help me understand why it wouldn't - for example, are you bringing your existing ALB into Copilot?

Lou1415926 avatar Dec 05 '23 23:12 Lou1415926