ЁЯПл The SchoolтА║ЁЯкк AWSтА║ЁЯЦея╕П рдзрдбрд╛ 07 тАФ EC2 рдореНрд╣рдгрдЬреЗ рдХрд╛рдп: screen рдирд╕рд▓реЗрд▓рд╛ рднрд╛рдбреНрдпрд╛рдЪрд╛ рдмрд╛рдХ-computer
ЁЯЦ╝я╕П See the drawing + lab ЁЯПа Course home ЁЯМ┐ Branch on GitHub тЬПя╕П View source
ЁЯЦ╝я╕П рдЖрдХреГрддреА рдЖрдгрд┐ labThe drawing + lab рдкреВрд░реНрдг рдкрд╛рдирд╛рд╡рд░ рдЙрдШрдбрд╛ тЖЧOpen full page тЖЧ

ЁЯЦея╕П рдзрдбрд╛ 07 тАФ EC2 рдореНрд╣рдгрдЬреЗ рдХрд╛рдп: screen рдирд╕рд▓реЗрд▓рд╛ рднрд╛рдбреНрдпрд╛рдЪрд╛ рдмрд╛рдХ-computer

ЁЯУН рддреБрдореНрд╣реА рдЗрдереЗ рдЖрд╣рд╛рдд: 12 рдкреИрдХреА рдзрдбрд╛ 07 тАФ рднрд╛рдЧ 2 рд╕реБрд░реВ! ┬╖ рдорд╛рдЧреЗ: lesson-06-iam-hygiene ┬╖ рдкреБрдвреЗ: lesson-08-types-pricing


ЁЯУж рдпрд╛ рдмреНрд░рдБрдЪрдордзреНрдпреЗ рдХрд╛рдп рдЖрд╣реЗ

рдзрдбреЗ 01тАУ06, рдЖрдгрд┐ рддреНрдпрд╛рд╕реЛрдмрдд: рдЬреНрдпрд╛рд╡рд░ рд╕рдЧрд│реЗ рдЪрд╛рд▓рддреЗ рддреНрдпрд╛ рдЧреЛрд╖реНрдЯреАрдЪреЗ рдЧреВрдв рдЙрдХрд▓рдгреЗ тАФ EC2 instance. рдЦрд░реА file:

ЁЯзТ 5 рд╡рд░реНрд╖рд╛рдВрдЪреНрдпрд╛ рдореБрд▓рд╛рд▓рд╛ рд╕рдордЬрд╛рд╡рд▓реНрдпрд╛рд╕рд╛рд░рдЦреЗ

Amazon computers рдиреЗ рднрд░рд▓реЗрд▓реНрдпрд╛ рдкреНрд░рдЪрдВрдб рдЕрднреНрдпрд╛рд╕рд┐рдХрд╛ ЁЯПл рдЪрд╛рд▓рд╡рддреЗ тАФ рдЬрдЧрднрд░рд╛рддрд▓реНрдпрд╛ рдЗрдорд╛рд░рддреАрдВрдордзреНрдпреЗ рд▓рд╛рдЦреЛ рдмрд╛рдХ. EC2 рдореНрд╣рдгрдЬреЗ рднрд╛рдбреНрдпрд╛рдЪрд╛ рдХрд╛рдЙрдВрдЯрд░:

"рдПрдХ рдмрд╛рдХ рджреНрдпрд╛. рд▓рд╣рд╛рди. Linux. рдореА рджрд░ second рдЪреЗ рдкреИрд╕реЗ рджреЗрдИрди рдЖрдгрд┐ рд╣рд╡реЗ рддреЗрд╡реНрд╣рд╛ рдкрд░рдд рдХрд░реЗрди." тАФ рдЖрдгрд┐ ~40 seconds рдирдВрддрд░, рдПрдХ рдмрд╛рдХ рддреБрдордЪрд╛.

рдмрд╛рдХ (instance) рд╣рд╛ рдЦрд░рд╛ computer рдЖрд╣реЗ: CPU, RAM, рдПрдХ disk, Linux. рддреБрдордЪреНрдпрд╛ рд╕рдореЛрд░рдЪреНрдпрд╛ laptop рдкреЗрдХреНрд╖рд╛ рддреЛ рддреАрди рдЧреЛрд╖реНрдЯреАрдВрдордзреНрдпреЗ рд╡реЗрдЧрд│рд╛ рдЖрд╣реЗ:

  1. Screen рдирд╛рд╣реА, keyboard рдирд╛рд╣реА. ЁЯЪлЁЯЦея╕П рддреБрдореНрд╣реА рддреНрдпрд╛рдЪреНрдпрд╛рд╢реА рдлрдХреНрдд network рд╡рд░реВрди рдмреЛрд▓рддрд╛ (SSH, HTTP тАФ рдзрдбреЗ 09тАУ10). "Server рдореНрд╣рдгрдЬреЗ screen рдирд╕рд▓реЗрд▓рд╛ рднрд╛рдбреНрдпрд╛рдЪрд╛ Linux computer" тАФ рд╕реБрд░реБрд╡рд╛рддреАрдкреВрд░реНрд╡реАрдЪреНрдпрд╛ guide рдиреЗ рд╕рд╛рдВрдЧрд┐рддрд▓реЗ рд╣реЛрддреЗ; рдЖрддрд╛ рддреЛ рддреБрдордЪрд╛ рдЖрд╣реЗ.
  2. рддреЛ рдПрдХрд╛ рдард░рд╛рд╡рд┐рдХ рдард┐рдХрд╛рдгреА рд░рд╛рд╣рддреЛ. рдПрдХ region (рд╢рд╛рд│рд╛ рдЬрд┐рд▓реНрд╣рд╛ тАФ ap-south-1 = Mumbai) рдЬреНрдпрд╛рдд availability zones рдЕрд╕рддрд╛рдд (рд╡реЗрдЧрд│реА рд╡реАрдЬ рдЕрд╕рд▓реЗрд▓реНрдпрд╛ рд╡реЗрдЧрд│реНрдпрд╛ рдЗрдорд╛рд░рддреА). рдЧрдВрднреАрд░ setups рдмрд╛рдХ рдЗрдорд╛рд░рддреАрдВрдордзреНрдпреЗ рдкрд╕рд░рд╡рддрд╛рдд, рдореНрд╣рдгрдЬреЗ рдПрдХ рдЖрдЧ тЙа рд╕рдЧрд│реЗ рдмрдВрдж.
  3. рддреЛ рдореБрджреНрджрд╛рдорд╣реВрди рд╡рд╛рдкрд░реВрди рдЯрд╛рдХрдгреНрдпрд╛рдЬреЛрдЧрд╛ рдЖрд╣реЗ. рднрд╛рдбреНрдпрд╛рдиреЗ рдШреНрдпрд╛, рд╡рд╛рдкрд░рд╛, рдкрд░рдд рджреНрдпрд╛. рд╕рдВрдкреВрд░реНрдг cloud рдорд╛рдирд╕рд┐рдХрддрд╛ рдПрдХрд╛ рд╕рд╡рдпреАрдд: рдмрд╛рдХ cattle рдЖрд╣реЗрдд, pets рдирд╛рд╣реАрдд тАФ k8s course рдордзреНрдпреЗ pods рдиреЗ рд╢рд┐рдХрд╡рд▓реЗрд▓рд╛ рддреЛрдЪ рдзрдбрд╛, рдПрдХ рдерд░ рдЦрд╛рд▓реА.

ЁЯЧ║я╕П рдЖрдХреГрддреА

flowchart LR
    subgraph region["ЁЯМП region ap-south-1 - the district"]
        subgraph aza["ЁЯПл AZ-a - one building"]
            desk["ЁЯЦея╕П i-0abcтАж your desk<br/>2 vCPU ┬╖ 1GB ┬╖ Linux<br/>no screen, network only"]
        end
        subgraph azb["ЁЯПл AZ-b - another building"]
            note["spread desks here too:<br/>one fire тЙа everything down"]
        end
    end
    you["ЁЯзСтАНЁЯТ╗ you, at home"]
    you -->|"1 SSH / HTTP over the network"| desk
    desk -->|"2 pay per second<br/>stop or hand back anytime"| desk

тЭУ рдХрд╛рдп

ЁЯдФ рдХрд╛

Pods рди рд╕рдордЬрддрд╛ рддреБрдореНрд╣реА EKS рд╡рд╛рдкрд░реВ рд╢рдХрддрд╛ тАФ рд╡рд╛рдИрдЯ рдкрджреНрдзрддреАрдиреЗ. AWS рдЖрдгрд┐ EC2 рдЪреЗрд╣реА рддрд╕реЗрдЪ: bills, incidents, capacity, "рдорд╛рдЭрд╛ node NotReady рдХрд╛ рдЖрд╣реЗ" тАФ рд╕рдЧрд│реЗ рд╢реЗрд╡рдЯреА рдХреБрдард▓реНрдпрд╛рддрд░реА рднрд╛рдбреНрдпрд╛рдЪреНрдпрд╛ рдмрд╛рдХрд╛рд╡рд░ рдпреЗрдКрди рдерд╛рдВрдмрддреЗ. рднрд╛рдЧ 2 рддреЛ рдмрд╛рдХ рдХрдВрдЯрд╛рд│рд╡рд╛рдгрд╛ рдЖрдгрд┐ рд╕рдордЬрдгреНрдпрд╛рдЬреЛрдЧрд╛ рдХрд░рддреЛ.

ЁЯзк рдХрд░реВрди рдкрд╛рд╣рд╛ (~10 рдорд┐рдирд┐рдЯреЗ, ~1┬в)

# rent one desk, fully wired (SG + role + boot script), from this repo:
cd ec2 && terraform init
terraform apply -var my_ip=$(curl -s ifconfig.me)/32     # review, type yes

# what did we just rent?
aws ec2 describe-instances --filters Name=tag:Name,Values=school-desk \
  --query 'Reservations[].Instances[].{id:InstanceId,type:InstanceType,az:Placement.AvailabilityZone,state:State.Name,ip:PublicIpAddress}'

# it's already a web server (lesson 12 explains how):
curl http://$(terraform output -raw public_ip)

# ЁЯз╣ THE LAB RULE тАФ always, before you leave:
terraform destroy -var my_ip=$(curl -s ifconfig.me)/32

тЬЕ рддрдкрд╛рд╕рд╛ тАФ рддреБрдореНрд╣рд╛рд▓рд╛ рдХрд╛рдп рджрд┐рд╕рд╛рдпрд▓рд╛ рд╣рд╡реЗ

aws ec2 describe-instances running рджрд╛рдЦрд╡рддреЛ; curl http://PUBLIC_IP user-data рдордзреВрди рдЖрд▓реЗрд▓реЗ рд╕реНрд╡рд╛рдЧрдд рдкрд╛рди рдкрд░рдд рджреЗрддреЛ.

ЁЯз╣ рд╕рд╛рдлрд╕рдлрд╛рдИ тАФ рдХрд╛рд╣реАрд╣реА рдЪрд╛рд▓реВ рдареЗрд╡реВ рдирдХрд╛

terraform destroy тАФ рдордЧ describe-instances рдиреЗ terminated рджрд╛рдЦрд╡рд╛рдпрд▓рд╛рдЪ рд╣рд╡реЗ (stopped рдмрд╛рдХрд╛рдЪреНрдпрд╛ рдбреНрд░реЙрд╡рд░рдЪреЗ bill рдЪрд╛рд▓реВрдЪ рд░рд╛рд╣рддреЗ)

тЪая╕П рдиреЗрд╣рдореАрдЪреНрдпрд╛ рдЪреБрдХрд╛

тПня╕П рдкреБрдвреЗ

рдмрд╛рдХ рд╡реЗрдЧрд╡реЗрдЧрд│реНрдпрд╛ рдЖрдХрд╛рд░рд╛рдВрдд рдЖрдгрд┐ payment plans рдордзреНрдпреЗ рдпреЗрддрд╛рдд тАФ scooters, trucks, season tickets рдЖрдгрд┐ standby seats. рд╣реБрд╢рд╛рд░реАрдиреЗ рдирд┐рд╡рдбрдгреНрдпрд╛рддрдЪ рдкреИрд╕рд╛ рдЖрд╣реЗ.

git checkout lesson-08-types-pricing

ЁЯЦея╕П Lesson 07 тАФ What is EC2: a rented desk-computer with no screen

ЁЯУН You are here: Lesson 07 of 12 тАФ Part 2 begins! ┬╖ Previous: lesson-06-iam-hygiene ┬╖ Next: lesson-08-types-pricing


ЁЯУж What's in this branch

Lessons 01тАУ06, plus: demystifying the thing everything runs on тАФ the EC2 instance. Real file:

ЁЯзТ Explain like I'm 5

Amazon runs gigantic study halls ЁЯПл full of computers тАФ millions of desks in buildings around the world. EC2 is the rental counter:

"One desk please. Small one. Linux. I'll pay by the second and hand it back whenever." тАФ and ~40 seconds later, a desk is yours.

The desk (instance) is a real computer: CPU, RAM, a disk, Linux. Three things make it different from the laptop in front of you:

  1. No screen, no keyboard. ЁЯЪлЁЯЦея╕П You talk to it only over the network (SSH, HTTP тАФ lessons 09тАУ10). "A server is a rented Linux computer without a screen" тАФ the before-you-start guide said it; now it's yours.
  2. It lives in a specific place. A region (school district тАФ ap-south-1 = Mumbai) containing availability zones (separate buildings with separate power). Serious setups spread desks across buildings, so one fire тЙа everything down.
  3. It's disposable on purpose. Rent, use, hand back. The whole cloud mindset in one habit: desks are cattle, not pets тАФ the same lesson pods taught in the k8s course, one layer down.

ЁЯЧ║я╕П Diagram

flowchart LR
    subgraph region["ЁЯМП region ap-south-1 - the district"]
        subgraph aza["ЁЯПл AZ-a - one building"]
            desk["ЁЯЦея╕П i-0abcтАж your desk<br/>2 vCPU ┬╖ 1GB ┬╖ Linux<br/>no screen, network only"]
        end
        subgraph azb["ЁЯПл AZ-b - another building"]
            note["spread desks here too:<br/>one fire тЙа everything down"]
        end
    end
    you["ЁЯзСтАНЁЯТ╗ you, at home"]
    you -->|"1 SSH / HTTP over the network"| desk
    desk -->|"2 pay per second<br/>stop or hand back anytime"| desk

тЭУ What

ЁЯдФ Why

You can use EKS without understanding pods тАФ badly. Same with AWS and EC2: bills, incidents, capacity, "why is my node NotReady" тАФ it all bottoms out at some rented desk somewhere. Part 2 makes that desk boring and knowable.

ЁЯзк Try it (~10 minutes, ~1┬в)

# rent one desk, fully wired (SG + role + boot script), from this repo:
cd ec2 && terraform init
terraform apply -var my_ip=$(curl -s ifconfig.me)/32     # review, type yes

# what did we just rent?
aws ec2 describe-instances --filters Name=tag:Name,Values=school-desk \
  --query 'Reservations[].Instances[].{id:InstanceId,type:InstanceType,az:Placement.AvailabilityZone,state:State.Name,ip:PublicIpAddress}'

# it's already a web server (lesson 12 explains how):
curl http://$(terraform output -raw public_ip)

# ЁЯз╣ THE LAB RULE тАФ always, before you leave:
terraform destroy -var my_ip=$(curl -s ifconfig.me)/32

тЬЕ Verify тАФ what you should see

aws ec2 describe-instances shows running; curl http://PUBLIC_IP returns the welcome page from user-data.

ЁЯз╣ Clean up тАФ do not leave running

terraform destroy тАФ then describe-instances must show terminated (a stopped desk still bills its drawer)

тЪая╕П Common mistakes

тПня╕П Next

Desks come in sizes and payment plans тАФ scooters, trucks, season tickets and standby seats. Choosing wisely is where the money is.

git checkout lesson-08-types-pricing
тЖР Previousiam hygieneNext тЖТtypes pricing

This page is the lesson's README from the lesson-07-what-is-ec2 branch, shown here so the whole School stays on one site. Code files open on GitHub at the same branch.