Skip to content

Latest commit

 

History

History
180 lines (147 loc) · 11.3 KB

AWS Steps.md

File metadata and controls

180 lines (147 loc) · 11.3 KB


Welcome to my tutorial


Let's dive in and discover the secrets of AWS. 🌊
I hope you benefit and enjoy it.🙏


From Zero to AWS Hero:🔥
Mastering Auto Scaling and Load Balancing for Seamless Deployments✨



Table of Contents:

1. Prerequisites

2. Steps

I. Creating an Auto Scaling Group

  • Signing in to your AWS account
  • Creating an Auto Scaling Group
  • Creating a Launch Template
  • Configuring the Launch Template
  • Adding Startup Script to Instances

II. Setting Up Load Balancers

  • Creating a Load Balancer
  • Configuring Load Balancer Settings
  • Creating a Target Group
  • Configuring Health Checks
  • Setting Group Size

3. Conclusion

4. Final Thoughts

Prerequisites:📝

Before we dive into the deployment process, ensure you have the following:

  1. An AWS account
  2. Your application code was uploaded to GitHub in a public repo.
  3. Familiarity with basic AWS concepts

Steps:👣💫

I. Creating an Auto Scaling Group:👥

1. Signing in to your AWS account:
Begin by signing in to your AWS account from this link 👉[AWS].

2. Set general settings: 🔗
Select a region that is geographically closer to your target audience. In my case I chose London.

image

  1. In the search par: 🔎
    write EC2 , then choose EC2 service

    image

  2. Creating an Auto Scaling Group:👥
    4.1 From the right side choose: Auto Scalling Group

    image

    4.2 Click on Creat Auto Scaling Group:

    image

    4.3 Choose a unique name for your Auto Scaling group.
    image

    4.4 Create a Launch Template:
    You can choose Launch Template if you have one, now we will create new one. The Launch Template contains instance configuration details.
    image

    4.5 Provide a descriptive name and useful description for your template.📜
    image

    4.6 Walkthrough on creating an optimal launch template to ensure smooth application deployment. I use this template, you may have to change something in it.
    image

    Use a key pair to securely connect to your instance. Ensure that you have access to the selected key pair before you launch the instance.
    image

    You can create Security group and add rules to allow specific traffic to reach your instance.
    image

    Scroll down to reach Advanced details
    image

    Scroll down to reach User data.
    image

    Write your script in the box.
    image

Here is my script with explanation for it: 📝

This script is for my Express JS project, you can write any script you want, but you have to make sure the script is good, you can test it in alone instance.

Your script may includes steps like:

  • Updating and upgrading packages
  • Installing Node.js and other dependencies
  • Creating user accounts for security
  • Downloading and deploying your app

#!/bin/sh
set -e

sudo apt update
sudo apt upgrade -y

# install nodejs repo to download the latest version then the node js
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install nodejs jq curl -y

# create app and github users, to run the application from them, without root, for security purposes
sudo useradd --system --create-home --shell /usr/sbin/nologin app
sudo useradd -g app --no-create-home --no-user-group --home-dir /home/app --shell /bin/bash github
sudo usermod --append --groups app github

# deploy the app

# Write the github acoount and repo in a variable
repo="SarahAbuirmeileh/Book-App"

# Creat a download URL to use it later
# Here we want to download a release which is ready to run.
download_url=$(curl "https://api.github.com/repos/$repo/releases/latest" | jq --raw-output '.assets[0].browser_download_url')

# Download the service file to run it as systemd service
curl -O "https://raw.githubusercontent.com/$repo/main/infrastructure/app.service"

# Adding the file to systemd and enable it, to run whenever the instance start
sudo mv app.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable app.service

# Creat a repository for the application, and download the app there, then dcompress the app and install the npm 
sudo -u app sh -c "mkdir -p /home/app/app && cd /home/app/app && curl -LO $download_url  && tar xzvf app.tar.gz  && npm install --omit=dev"

sudo reboot
# Evrything is done !!!



Create the template.
image

4.7 Move back to the Auto Scaling group and choose your template.
image

Note: If your template didn’t appear, you may need to refresh the template.
image

4.8 Choose the latest version (optional), then click next.
image

4.9 Choose the Availability Zones

  • It’s recommended to choose as possible as you can
  • The number of Availability Zones may be different from one region to another.
    image

    Now let’s move to the next part.
    image


II. Setting Up Load Balancers📦
Fine-tune Load Balancer settings to optimize traffic distribution and improve availability.

1.1 Creat a Load Balancer and choose the type of it.
You can choose ‘Attach to an existing load balancer’ if you already have one, now we’ll creat new one.
image

1.2 Write the name of your Load Balancer and choose the scheme.
Internet-facing is designed to distribute incoming traffic from the internet to multiple targets.
image

1.3 Creat target group
Configure a Target Group to manage routing traffic to instances effectively.
image

Choose the target group name
image

1.4 Let the VPC Lattice integration options to the default value and enable the Turn on Elastic Load Balancing health checks
image

1.5 Choose the Health check grace period according to your requirements.
Set up health checks to monitor the instances’ status and replace unhealthy instances automatically.
image

1.6 Choose the Group size : Desired, Minimum, Maximum.

  • Determine the appropriate group size based on your application’s needs and ensure high availability.
  • It’s recommended to have a minimum of 2 instances because if one fails there will be another one.
    image

    1.7 Enable instance scale-in protection (optional)
    You can choose Scaling policies
    image

    1.8 You have to see something like this 😁
    image

    1.9 If you go to the EC2 instances you’ll see the your desired number of your instances is generated automatchly.
    image

    5.10 Go to your target group to check the health of your instances.
    image

    5.11 If you want to delete this work, you should start by deleting your Auto Scaling group.
    image



Conclusion:📌

Congratulations! By following this comprehensive guide, you’ve successfully learned how to deploy your application using AWS Auto Scaling Groups and Load Balancers. This process ensures high availability, fault tolerance, and efficient scaling for your applications. Now, you’re ready to take your AWS deployment skills to the next level and build robust, scalable applications.

Final Thoughts:📃

Deploying applications on AWS can seem daunting, but with this step-by-step guide, you’re equipped with the knowledge needed to navigate the process seamlessly. Remember, practice makes perfect. Feel free to experiment with different settings and configurations to tailor the deployment to your specific project’s needs.