How to create a new service

Let's say we want to create a new service we call mc-kafka which will provide a kafka consumer dashbboard. This page will show the steps how to achieve this on the AWS platform, let's start!

Create a subdomain/route on Route 53

First we will create a subdomain. We can do this by going to Route 53

  • Navigate to the hosted zones and select mychannels.cloud.
  • Click Create Record set
  • Fill in the name of the new subdomain
  • Set alias from no to yes and pick the MyChannels Application load balancer
  • Finish by clicking the create button

When we followed this steps we now have traffic directing from the subdomain to the application load balancer.

Application load balancer subdomain setup

Our MyChannels application load balancer has listening rules where we configure how to redirect traffic. First we determine the host header and link that with the correct target group. However before we can do that we need to create a target group.

  • Go to target groups in EC2 dashboard
  • Click create target group
  • Fill in the name, in our case we use mc-kafka
  • Choose target type IP
  • Define the correct port you want to listen to, in our case 8080
  • Select the MyChannels VPC
  • Click create to finish creating the target group

We now created the target group and we can create the listener in the load balancer.

  • Go to the port 443 listener rules
  • Click on the top navigation Add rules
  • Click insert rule
  • For the if match column select the host header and fill the host you want to match, we will fill in mc-kafka.mychannels.cloud
  • For the then column we select the forward to and select the target group you just created. In our case this is mc-kafka

ECS Setup

We now have setup a route for our traffic from the subdomain through the application load balancer and it is time to create the service itself. At MyChannels we use AWS ECS Fargate for this, but before we setup the service we need to create a security group. A security group is like a firewall where you open and close ports to certain or all traffic sources. This can be a specific IP or another security group for example. Let's create a security group for mc-kafka:

  • Go to the EC2 Dashboard - Security groups
  • Click Create Security Group
  • Name the security group, in our case it would be mc-kafka
  • Setup the inbound ports (you probably want to setup the inbound port towards the ALB with the sg-0ac1ce33654a6635f as source)
  • Click 'create'

We now have a security group and go to ECS. We first need to setup a task definition where we define the resources, environment variables and the container we want to run. Create a task definition

  • Go to ECS task definitions
  • Click Create new Task Definition
  • Select the AWS Fargate option
  • Fill in the name and select the EcsTaskExecutionRole
  • Pick the task size (memory/CPU)
  • Add a container (from ECR or docker.io) with environment variables and port mapping
  • Click Create

Now that we have a task definition the only thing left to do is to create an ECS service.

  • Go to ECS clusters and select the correct cluster (production or test)
  • Click Create on the services tab
  • Select launch type FARGATE
  • Select the correct task definition
  • Select the correct Cluster
  • Fill in the service name
  • Define number of tasks
  • Pick rolling updates for deployments (blue/green deployment needs two target groups)
  • Click Next step
  • Configure Network by Choosing the correct VPC, subnets and target group
  • Click Next step
  • Setup autoscaling if needed and click next step
  • Review once again and click create

Congratulations, you now have a new service running.

Last Updated: 7/15/2019, 4:14:25 AM