Happenn
  • Introduction
  • System Architect
  • For Dev
    • AWS
      • Domain & CNAME
      • Rescale Instance
      • Request AWS Certificate
      • Generate Certificate with Certbot
      • S3
      • SSH & FTP
      • Auto Scaling
      • RDS MySQL
    • Digital Ocean
      • Virtual Host & Certificate
      • SSH & FTP
    • Server
      • Git
      • Setup the Server
    • Code
      • Laravel/Lumen
      • Vue.js
      • Webpack
      • JavaScript Library
        • Lodash
        • axios
        • Moment.js
      • Code Style Guide
      • Useful Tools
    • HAM Admin
      • Install locally
      • Deploy
    • Happenn API
      • Install locally
      • Install DB locally
      • Make DB changes
    • Happenn IO
      • Install locally
    • Happenn Virtual
      • Install locally
      • Folders and file structure
      • Deploy code
        • Happenn AWS
        • Delegia AWS
    • Happenn Event app
      • Deploy
      • Install locally
Powered by GitBook
On this page
  • Load Balance
  • Create AMI and setup for Auto Scaling Groups
  • Create AMI from Existing Instance
  • Update Launch Template
  • Increase/Decrease EC2 Instance
  • Add New Reader Instance for RDS
  • (RDS) Change Another Instance to Writer
  • Add RDS Replica
  1. For Dev
  2. AWS

Auto Scaling

Load Balance

Load Balancer helps handle the request from 1 endpoint to 1 or more instance of the server. Normally, if we have 2 servers, the first request, will go to server A. Then, the second request will be send to server B instead. And the next one will be server A.

This means that, to make the server performs better. We can just add more server instance instead to share the work loaded. However, this also mean that, there are more servers we have to tend to. This also including how the server handle the local file if any.

There are 2 ways of scaling the server

  • Vertical Scaling - Adding more resource to the server such as increase more RAM

  • Horizontal Scaling - Adding more server into load balancer

Both ways have the same cost for the same amount of resources but, with Horizontal Scaling, we do not need to keep config the server every time there is a change to the server resource.

As we have prepared code to be able to support the Horizontal Scaling and still functioning the same way. Including the way we have to upload the code to the server now. So, the developer no longer needs to update the code on each server.

While upgrading the server size, the server has to go down first until it finish the upgrade. Adding more instance, however, does not required any down time. As, it is just create another server, and until the server is ready, the load balancer will not give the request to that server.

Create AMI and setup for Auto Scaling Groups

Create AMI from Existing Instance

  • Go to AWS - EC2 page > Instances

  • Select a single instance

  • Click on Actions > Image and templates > Create image

  • Enter Image name

    • Should try checking on existing IAM to understand how to name the image to make it easier to mange

  • Click Create image

  • This process mays take a while, and will down a server a few minutes

Update Launch Template

  • Go to AWS - EC2 page > Launch templates

  • Select a single template

  • Click on Actions > Modify template (Create new version)

  • Assign Template version description

  • on Application and OS Images (Amazon Machine Image)

  • Select My AMIs > Owned by me

  • Select the AMI you want to replace the current one

  • Click Create template version

  • Back to Launch templates page

  • Select above instance

  • Click Actions > Set default version

  • Choose the template version you want as default

  • Click Set as default version

Increase/Decrease EC2 Instance

As we have a main server for each server, the minimum amount of the server we required on normal day should be 0. As this mean, it will has 1 server up and running. So, increase the server in Auto Scaling Group by 1 will mean, we have 2 servers.

  1. Go to AWS console and select service EC2.

  2. On the left panel, select Auto Scaling Groups from Auto Scaling section.

  3. Click on the name of the Auto Scaling Groups you want to update.

  4. You will be in the Details tab. Click Edit on Group Details.

  5. Change the Desired Capacity to the amount of the number of instance you want. If it is more than Maximum capacity. Just increase this number as well. Then click Update.

  6. After a few minutes, it will create or delete the instance(s) in Instances page.

Add New Reader Instance for RDS

With multiple reader instances, when connect to Cluster endpoint, it will share the request between all the instance. This will help ease the load on a single instance.

  • Go AWS - RDS page > Databases

  • Select a single Regional cluster

  • Click Actions > Add reader

  • Instance configuration

    • select which size of the new instance should be

  • Connectivity > Public access

    • If it is for Writer Instance, should always be Publicly accessible

      • This is to allow our Digital Ocean be able to access the RDS

  • Click Add reader

(RDS) Change Another Instance to Writer

  • Go AWS - RDS page > Databases

  • Select a single Writer instance

  • Click Actions > Failover

Add RDS Replica

Need to contact AWS support, as the happenn-api can no longer create replica

For RDS, as we can only has 1 Database but we have to add Reader Instance instead to make it act the same way as the Load Balancer for EC2.

  1. Go to AWS console and select service RDS.

  2. From left navigation, click on Databases.

  3. Click on happenn-api. (Should be the first one with Role: Regional Cluster)

  4. Click Actions at the top right and click Add replica auto scaling.

  5. In the page

    1. Policy Name - Can be anything.

    2. Target Value - The default is 50% of the CPU has been reached.

    3. Cluster Capacity Details

      1. Minimum Capacity - Specify the initial number of the Reader instance.

  6. Click Add policy.

This process will take sometime before it kick in as it need to create a new Reader Instance.

PreviousSSH & FTPNextRDS MySQL

Last updated 2 years ago