AWS Classroomnotes 11/Sep/2022

Different Resources/Services Attached to EC2

  • AWS EC2 instance should be created in some AZ.
  • By default in every AWS region, AWS pre-creates a default vpc with subnet for each AZ.
  • While creating the ec2 instance, we can select AZ by selecting subnet
  • When we select a subnet an Elastic Network Interface (ENI) will be getting a private ip and will be attached to ec2 instacnce.
  • Public ip is enabled by default.
  • Public ip is not charged by default, when we create an ec2 instance AWS has a large pool of available public ips and one public ip will be used for mapping public ip to private ip.
  • When we shutdown the ec2 instance, the public ip is released & will go back to aws public ip pool.
  • So thats the reason the public ip changes after stopping and starting the ec2 instance.
  • If we need same ip even after restart, then we need go pay for static ip address which is referred as elastic ip.
  • AWS also gives a dns name for public ip and private ip (in default vpc’s).
  • To filter out which traffic that is allowed to your ec2 instance, we use security group
    Preview
  • To login into ec2 instance we need credentials i.e. key pairs
  • For now i will be using existing key pair created in previous session
    Preview
  • Lets create a security group which allows ssh connection from any where (SSH => 22 port)
    Preview
    Preview
    Preview
    Preview
    Preview
    Preview
  • Lets select an AMI (Amazon Machine Image). See below for basic AMI intro
    Preview
    Preview
    Preview
  • Now lets select Network Settings
    • Public ip or not
    • Which AZ
    • Which Security Group
      Preview
      Preview
      Preview
      Preview
      Preview
  • Lets connect to this ec2 instance
    • Command ssh -i <path to pem> username@<ip address>
      Preview
      Preview
  • Lets look at
    • ENI
      Preview
    • EBS Volume
      Preview

Activity 1:

  • Create a new key pair called as ec2learning.pem in the region of your choice
  • Create a new security group which open
    • tcp 22 port for every one
    • tcp 80 port for every one
  • Create an ec2 instance in the AZ-B
  • Ensure the machine has public ip
  • Create the instance with ubuntu 18.04
  • Login into the ec2 instance and execute the following commands
sudo apt update
sudo apt install apache2 -y
sudo apt install stress -y

Activity 2

  • We are generating a key pair by using AWS
  • Now lets create a Key pair on your laptop and upload the public key to AWS
  • Launch Powershell and execute ssh-keygen
    Preview
  • Now navigate to ~\.ssh
    Preview
  • id_rsa => private key
  • id_rsa.pub => public key
  • Now open key pairs section from ec2 console
    Preview
    Preview
    Preview
  • Now repeat Activity 1 with imported key pair
    Preview
  • Login into ec2 instance (ubuntu 18) ssh -i ~/.ssh/id_rsa ubuntu@<publicip>
    Preview
    Preview
    Preview
  • Note: Delete all the instances after usage.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner