Apr 3, 2018

Runnning .NET Core app on Amazon EC2, part 2

I am running .NET Core apps on Amazon EC2 new images, the part 1 is here.
In Part 1 I got the app running using simple Nginx configuration, but apart from Nginx, there are other options. This should not be full web server, since all the requests are processed by Kestrel already, so just a proxy or load balancer could fit. I was told Traefik is a good option, so let's try it.
Traefik is a dynamic load balancer that integrates with different infrastructure orchestrators, but we need only simplest static config and that's quite simple to do - go get the Traefik:
sudo wget -O /usr/local/bin/traefik "https://github.com/containous/traefik/releases/download/v1.6.0-rc3/traefik_linux-amd64"
Make it executable:
sudo chmod +x /usr/local/bin/traefik
Create config file:
sudo mkdir /var/traefik
cd /var/traefik/
sudo nano simple.toml
And put following content in it:
[entryPoints]
        [entryPoints.http]
        address = ":80"
[file]
[backends]
        [backends.back1]
                [backends.back1.servers.s1]
                url = "http://localhost:5000"
[frontends]
        [frontends.front1]
        backend = "back1"
        [frontends.front1.routes.site]
        rule = "Host:ec2-34-241-215-56.eu-west-1.compute.amazonaws.com"
Create and start .NET Core application as daemon (described here)
And now it is left to start reverse proxy, it also could be run as daemon but I'll simply run from console:
sudo /usr/local/bin/traefik --configFile=/var/traefik/simple.toml
And that's it! Additional perk of Traefik is its Let's Encrypt integration, but I was not able to configure that for my EC2 instance-based app despite spending a couple of hours, so maybe that's the quest for the next time. Don't forget to stop/terminate EC2 instances after trying, or that may cost you some money if you are above the free tier or not using it.

1 comment:

Bree Bites said...

Thanks forr writing this