Overview
Create AWS Certificate
To support HTTPS, We need to create a certificate. I’ll use an AWS certificate.
Add your domain name. e.g., *.yourDomain.com
That’s it. Let’s create Load Balancer
Create AWS Load Balancer
The load balancer connects to the ECS service through a fixed DNS. If you have your domain address, you can register Load Balancer’s DNS as CNAME and use it.
First, select Load Balancing from the list of EC2 services.
This part is essential. Let’s add HTTPS.
Please set up the VPC of the ECS created in the previous post.
I choose the certificate which is made on AWS.
Leave only 0.0.0/0 in Source and delete the ‘::/0’. ‘::/0’ is used by ipv6.
The vapor app uses 8080 as the default port. Let’s set the routing port to 8080.
A health check is a path that periodically checks whether the server is operating correctly. Health Check is straightforward to set up in the Vapor app.
//Set HealthCheck
app.get("health") { req in
return "OK"
}
Whether the server is running correctly every 120 seconds, that is, every 2 minutes.
The setting is done. Simple, isn’t it?
Don’t forget to check if the Target Group of Load Balancer is also adequately created.
Create ECS Service
Let’s create a new service that runs on ECS Container. I’ll set a load balancer for it.
The tasks are pending because our server can’t access the RDS. I’ll resolve it by setting the inbound rule for RDS.
Setup inbound of RDS
Now the tasks that run on ECS are working fine.
Setup ‘forward rule’ on Load Balancer
To access your server, You should set up the ‘forward rule’ on LoadBalancer. Do you remember our load balancer listens to two-port? HTTP and HTTPS.
Let’s set up the ‘forward rule.’
Check your Load Balancer. You can see there is two Listener ID.
Set HTTPS, Forward to ECS Clusters load balancing target group.
Set HTTP, Forward to ECS Clusters load balancing target group. (Yes, It’s the same as HTTPS)
That’s all. Now you can access your Vapor Server by using the DNS name. Copy and Pasted it to your web browser and then check whether it can access or not.
Setup your DNS Name, CName on Namecheap.com
Do you have your domain? The last step is to set up your domain with an AWS load balancer and certificates.
Go to AWS Certificate Manager. Check your CNAME and Value.
I’m using NameCheap.com. So If you bought a domain at NameCheap.com, then go to the advance DNS setup at NameCheap.com.
You have to register two CNAME records. One is AWS Certificates the other one is Load Balancer’s DNS.
-
AWS Certificates
-
AWS Certificate Manager -> Domain
-
-
Load Balancer’s DNS
-
EC2 -> Load Balancers -> Description -> DNS Name
-
Conclusion
I introduced how to set up your vapor app using the Load Balancer. There are many steps you have to set up. I don’t think It’s complicated. Once you set it up, then you can easily set up your vapor app next time. I hope you enjoy reading my posts.











































