In SWARM, we use these comprehensive step-by-step guides to build a production-ready devops solution.

Application Pipeline Setup (Overview)

image alt text

  1. ECR Repositories

    Create ECS Repositories first, where the Dev team could build and push the application’s Docker image.

  2. Target Groups

    Target Groups are referenced by Load Balancer. Let’s create them before doing Load Balancer.

  3. Load Balancer

    After a Load Balancer is created, you will get a DNS name(A Record) of it. Point all your site domain name to this DNS name. image alt text

  4. ECS Cluster ECS Cluster is a container, where we can create Task Definitions and Services. An EC2 instance will also be created automatically while creating the ECS Cluster.

  5. ECS Task Definitions

    Specify which Docker image should be used, how much CPU and memory to use, whether should the console logging message redirect to CloudWatch.

  6. ECS Services

    Specify how many tasks should be run, which Task Definition should be use, which Target Group as well as Load Balancer should be register to.

  7. EC2 instance

    EC2 instance are created within ECS Cluster. We need to add an Inbound rule letting the Load Balancer redirect requests to.

Pipeline Components Setup (Detail Operations)

Target Groups setup

  1. AWS console ⇒ EC2:

    image alt text

  2. Target Groups ⇒ Create target group

    image alt text

  3. Create 2 groups

    • Ludlow2-api-qa
    • Ludlow2-api-prod

    The port doesn’t matter, keep it as default: 80.

    VPC: pick one, make sure it is the same as the one in your Load Balancer and EC2 Instance.

    image alt text

  4. After the target group created, double check tab “Health checks”, and make sure your server will return a code within “Success codes” on the path “/”.

    image alt text

Load Balancer setup

  1. AWS console ⇒ EC2 ⇒ Load Balancers ⇒ Create Load Balancer

    image alt text

  2. Select: Application Load Balancer

    image alt text

  3. Add 2 Listeners: HTTP / HTTPS, Select All Availability Zones.

    image alt text

  4. Choose a certificate

    image alt text

  5. Select an existing security group: default

    image alt text

  6. New target group or Select existing one: Ludlow2-api-prod. Port doesn’t matter, keep it as default: 80.

    image alt text

  7. No need to Register Targets, which will be register automatically by our ECS Services.

    image alt text

  8. Review and Create

    image alt text

  9. Select the new created Load Balancer: Ludlow2 ⇒ Listeners: 80/443 ⇒ View/edit rules

    image alt text

  10. Add a rule: If Host is qa.ludlow.io forward to Target Group: Ludlow2-api-qa

    image alt text

EC2 Instance setup

The EC2 instance where we need to add an inbound rule letting a Load Balancer redirect the request, should be created while creating ECS Cluster below.

  1. AWS console ⇒ EC2 ⇒ Instances ⇒ Ludlow2 ⇒ click Security groups

    image alt text

  2. Inbound ⇒ Edit

    image alt text

  3. Add Rule, Type pick All TCP, Source input the Security Group ID(sg-964aa2ef) from Load Balancer: Ludlow2

    image alt text image alt text

ECS Cluster setup

  1. AWS console ⇒ Elastic Container Service:

    image alt text

  2. Clusters ⇒ Create Cluster

    image alt text

  3. Select EC2 Linux + Networking

    image alt text

  4. Use default EC2 instance.

    image alt text

  5. Networking use existing VPC, Subnet, and Security group. Security group should be the same as the one in Load Balancer, i.e. default.

    image alt text

ECR Repositories setup

  1. AWS console ⇒ Elastic Container Service ⇒ Repositories ⇒ Create repository

    image alt text

  2. Create two repositories: ludlow2-api-qa, ludlow2-api-prod.

    image alt text

  3. Write down the commands, which will be used in CI platform: TeamCity.

    image alt text

ECS Task Definitions setup

  1. AWS console ⇒ Elastic Container Service ⇒ Task Definitions ⇒ Create new Task Definition

    image alt text

  2. Select EC2 as launch type compatibility

    image alt text

  3. Configure task and container definitions

    image alt text

  4. Add container

    image alt text

  5. Standard configuration:

    • Image points to the Repository we just created: ludlow2-api-qa

    • Memory Limits should set to Hard limit for qa, just in case of affecting the prod Task’s memory

    • Port mappings: Host port must be set to 0, in order to register to a Target Group with a dynamic port, which allow two different Tasks(Blue/Green Deployment) running at the same time, one for old version image, one for new version image. Container port is whatever you set in application’s Dockerfile.

    image alt text

  6. Advanced container configuration

    • STORAGE AND LOGGING ⇒ Log configuration ⇒ check Auto-configure CloudWatch Logs, this makes sure all the console log will go to CloudWatch.

    image alt text

ECS Services setup

  1. AWS console ⇒ Elastic Container Service ⇒ Clusters ⇒ Ludlow2

    image alt text

  2. Services ⇒ Create

    image alt text

  3. Configure services

    image alt text

    • Make sure Maximum percent * Number of tasks >= Number of tasks + 1, letting your new task can be started while the old one is stopping.
  4. Configure network

    • Load balancer type: Application Load Balancer

    image alt text

    • Select Load Balancer: Ludlow2, Click Add to load balancer

    image alt text

    • Target group name, pick Ludlow2-api-qa

    image alt text

WebApp Pipeline Setup

image alt text

S3 Bucket setup

  1. AWS console ⇒ S3:

    image alt text

  2. Create bucket

    image alt text

  3. Name and region: put a name, e.g. ludlow-frontend

    image alt text

  4. Take the default settings and Create bucket

    image alt text

CloudFront setup

  1. AWS console ⇒ CloudFront:

    image alt text

  2. Create Distribution

    image alt text

  3. Pick Web as the delivery method

    image alt text

  4. Origin Settings:

    • pick the S3 Bucket just created. E.g. ludlow-frontend.s3.amazonaws.com

    image alt text

  5. Default Cache Behavior Settings:

    • Viewer Protocol Policy: Redirect HTTP to HTTPS

    image alt text

  6. Distribution Settings

    • Alternate Domain Names(CNAMEs): your app’s url. E.g. app.ludlow.io

    • SSL Certificate: check Custom SSL Certificate, and pick the certificate to your app.

    • Default Root Object: index.html or any html file you want to load “/”

    • Others: keep them as are.

    image alt text

  7. Click Create Distribution and you’re all set.

    image alt text

  8. After the Distribution is created, you can have its Domain Name: d19daj4piv5qj9.cloudfront.net.

    image alt text

  9. You must create a CNAME record with your DNS service to route queries for api.ludlow.io to d19daj4piv5qj9.cloudfront.net

    image alt text

  10. If you got 403 error when you open the link of the CloudFront, check here