ecs-patterns: Simple http -> https redirect
See original GitHub issueAdd a property to ecs-patterns constructs to automatically setup an http->https redirect on the service’s load balancer.
Use Case
User’s with publicly accessible services using https usually want to automatically redirect clients from http to https.
As the result of discussion within https://github.com/aws/aws-cdk/issues/5583, it is apparent that setting this up could be much easier. Since this is a super common pattern and one that we should encourage for publicly accessible services, we should make it as easy as possible in the high level patterns constructs.
Proposed Solution
Add an optional property redirectToHttps
or forceHttps
that when set to true
will create a listener on port 80 that redirects to 443. This option should only be able to be set to true when a certificate is provided. This should be added to all ecs-patterns constructs that create load balancers.
- 👋 I may be able to implement this feature request
- ⚠️ This feature might incur a breaking change
This is a 🚀 Feature Request
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:13 (5 by maintainers)
Top GitHub Comments
Hey! I think this already works… let me know if I’m wrong!
Here’s how I implemented HTTP -> HTTPS redirects on the load balancer (single file implementation, < 60 lines, should be easy to follow): https://github.com/khalidx/origin/blob/master/src/cdk.ts
I’ll inline the implementation here for reference:
By the way, check out https://github.com/khalidx/origin for a boilerplate starter project that deploys a node express API as an HTTPS exposed service using CDK. It also generates a node module, native binaries, and Docker image for your API, so that it can run anywhere!
It seems this is now possible using the
addRedirect
methodhttps://docs.aws.amazon.com/cdk/api/v1/docs/aws-elasticloadbalancingv2-readme.html#:~:text=If you do not provide any options for this method%2C it redirects HTTP port 80 to HTTPS port 443.