copilot-cli
copilot-cli copied to clipboard
feature request: ALB supports Host Header
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?
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!
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?
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.
Thanks @iamhopaul123 for the update. Is there any plan to add this feature?
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.
yes, got the same thought to have a custom domain name.
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 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 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.
@bvtujo Would you be able to help add custom-headers to this? I would really appreciate it ^_^
@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
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 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?