Skip to content

Latest commit

 

History

42 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CloudAppExercise - Eldan

Intro

This git repo has an example flask app for user db (for Arsenal FC fans) along with a Dockerfile to make an image for the app. The goal of the exercise is to deploy this app via docker container in an AWS EC2 instance and later on use a load balancer and auto scaling group for traffic managment. the Arsenal logo image is also used via an s3 storage object (public) (at the end of the README there will be notes for making an EC2 instance work with a private bucket using boto3 and an IAM role)

NOTE: the database in the app is local for the instance (since its just an example app), so when multiple instances are up the data presented may not be the same or up to date.

Deployment instruction - For single EC2 instance

  1. Clone the repository to the local/virtual machine with git clone (install it if missing)
  2. In case you don't have docker installed, use the following manual to install Docker:
    1. for Amazon-Linux - https://medium.com/@srijaanaparthy/step-by-step-guide-to-install-docker-on-amazon-linux-machine-in-aws-a690bf44b5fe
    2. for Ubuntu - https://docs.docker.com/engine/install/ubuntu/
  3. Change directory to the repo directory (where the Dockerfile is saved) and in the terminal insert the following commands:
    1. docker build -t myarsenalapp .
    2. docker run -d -p 5000:5000 myarsenalapp
  4. Using the Public IP for the EC2 or localhost open an internet tab in port 5000:
EC2_running 5. The app is up! App_running

Deployment instructions - launch template and NLB

  1. create an ec2 instance as previously showed (EC2 settings): !instance_settings

  2. Use the following sg-rules (inbound from anywhere): sg_rules

  3. after making sure the app works properly (as done previuosly)

  4. select the running app --> actions --> Images and templates --> Create template from instance launch_template

  5. keep everything as as and scroll down to advanced settings

  6. in the User Data section paste the following: user_data_bash

#!/bin/bash

sudo yum update -y

sudo yum install git -y

git clone https://github.com/eldankit/CloudAppExercise

cd ..

cd ..

cd CloudAppExercise/

sudo yum install docker -y

sudo systemctl start docker

sudo systemctl enable docker

sudo usermod -a -G docker $(whoami)

newgrp docker

docker build -t myarsenalapp .

docker run -d -p 5000:5000 myarsenalapp
  1. create the launch template

  2. go to launch templates section and select the created template, go to Actions --> launch instance from template and make sure that the app is running as before.

    launchtemplate-testtemplate
  3. go to Load Balancers and create a new network load balancer. make sure to select all the subnets and make a listener to port 80 and at the target group section click create target group.

  4. at the target group select tcp protocol and select port 5000, at the healthcheck also make sure to use the tcp protocol and create the target group. the target group was set as follows:

tg-settings
  1. at the load balancer creation page select the one that you created and create the NLB.
  2. Create an Auto Scaling Group with the following settings:
asg-settings1 asg-settings2 asg-settings3 asg-settings4 asg-settings5 asg-settings6
  1. to see that the ASG+NLB works go to the Target group and see that it's healthy:
tg-healthy
  1. afterwards, go to the NLB and find the NLB DNS:
LB-DNS
  1. open a new web browser tab with the DNS and see that the webapp works:
LB_app_running
  1. to check that the ASG works, at first terminate the instance and see that it was recreated, then connect to the instance that is up and use the stress command:
stress_test
  1. afterwards wait and see that another instance is set up:
LB_testing
  1. the set up is complete!

EC2 with a private s3 bucket

in order to use an EC2 instance with a private s3 bucket we first need to set up an IAM role with the following permisiions:

IAM-role-s3

then assign the role to the EC2 instance (or launch template) so that the bucket is accessible when the app is running.

That's it!

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages