Creating an EC2 Instance

Published on Author craigzearfossLeave a comment

EC2 stands for Elastic Cloud Compute




This example uses Ubuntu Server 14.04 LTS.
Before you begin make sure you have a key pair (You can also do this later.)

  • Click on “EC2 Dashboard”.
  • In the left menu select “Key Pairs” under “Network & Security” and then click on the “Create Pair” button.
  • Follow the instructions.



Launching an EC2 InstanceTop

  1. Choose an Amazon Machine Image (AMI)
    • Select Ubuntu Server 14.04 LTS (HVM), SSD Volume Type – ami-fce3c696.
  2. Choose an Instance Type.
    • Select t2.micro.
    • Click “Next: Configure Instance Details”
  3. Configure Instance Details.
    Number of instances 1
    Purchasing option leave unchecked
    Network select one of you VPCs
    Subnet select one the the subnets for the VPC you selected
    Auto-assign Public IP Enable (Use disable if you do not want this instance accessible through a public ip)
    IAM role None
    Shutdown behavior Stop (Terminate will delete the instance when it is shut down)
    Enable termination protection leave unchecked
    Monitoring leave unchecked
    Tenancy Share – Run a shared hardware instance
    • Don’t make any changes to Network interfaces or Add Device.
    • Click “Next: Add Storage”.
  4. Add Storage.
    • Usually don’t change anything.
    • Click “Next: Tag Instance”.
  5. Tag Instance.
    • At least add a tage for the Name.
    • Click “Next: Configure Security Group”.
  6. Configure Security Group.
    Type Protocol Port Range Source
    SSH TCP TCP My IP – #.#.#.#
    HTTP TCP TCP Anywhere 0.0.0.0
    HTTPS TCP TCP Anywhere 0.0.0.0

  7. Add more as needed..
  8. Click “Review and Launch”.
  9. Review and Launch.
    • If everything looks good then click “Launch”.
    • You’ll be prompted for a key pair. If you already have one you want to use then select it. Otherwise, select “Create a new key pair”.
    • Click the acknowledge check box.
    • Click “Launch Instance”.
    • Click “View Instance”.
    • For configure security group:
      SSH source=My IP
      HTTP source=anywhere
      HTTPS source=anywhere



Connecting to an EC2 InstanceTop

  • Connect via ssh (Instructions assume you are on Linux)
    • Download the .pem file.
    • Open a command terminal.
    • Update the file permissions on the .pem file.
      chmod 600 PEM_NAME.pem
    • Connect to the server
      ssh -i PEM_NAME.pem ubuntu@PUBLIC_IP_ADDRESS
    Copying files

    To copy a local file to the AWS instance use scp. For example,

    scp -i PEM_NAME.pem /tmp/my_file.txt ubuntu@PUBLIC_IP_ADDRESS:/tmp/my_file.txt

    To copy file file from the AWS instance to your local computer use scp. For example,

    scp -i PEM_NAME.pem ubuntu@PUBLIC_IP_ADDRESS:/tmp/my_file.txt /tmp/my_file.txt

  • Connect via the web
    • Click on “EC2 Dashboard”.
    • Click on “Running Instances” link.
    • Select an instance in the list by clicking on the checkbox.
    • Click on the “Connect” button at the top.
    • Select “A Java SSH Client directly from my browser (Java required)”
      Public IP (this will be your public ip)
      User name for Ubuntu instances it will be ubuntu
      Key name the key pair .pem file
      Private key path enter the path to the shown .pem file
      Save key location store in browser cache
    • When prompted click “Run”.
    • Accept the license agreement.
    • If prompted that the MindTerm home directory does not exist, then click “Yes” to create it.
    • If prompted tthat host key does not exist, then click “Yes” to create it.
    • If prompted to add this host to your set of known host, the click “Yes”



Elastic IPsTop

  • Click on “EC2 Dashboard”.
  • In the left click on “Elastic IPs” in the “Network & Security” section.
  • Click on “Allocate New Address”. (Elastic IPs may show up on you Amazon charges.)
  • Select the new Elastic IP and under the “Acttions” dropdown select “Associate Address”.



Changing a Host NameTop

  • Edit the file /etc/sysconfig/network.
    sudo nano /etc/sysconfig/network
  • Change the HOSTNAME.



Changing the Time ZoneTop

  • The default time zone is UTC.
  • ssh to the server.
  • Locate the time zone information.
    cd /usr/share/zoneinfo/
    ls -l
  • Assume we are in America.
    cd America
    ls -l
  • Edit the file /etc/sysconfig/clock.
    sudo nano /etc/sysconfig/clock
  • Change to one of the time zones that you saw in the listings above. For example, America – Chicago.
    ZONE="America/Chicago"
    UTC=false
  • Add a symbolic link to the local time file. Using America – Chicago, for example,
    sudo ln -sf /usr/share/zoneinfo/America/Chicago /etc/localtime



Adding a VolumeTop



Adding a SwapTop

  • In the EC2 Dashboard verify that the availability zone for the EC2 instance that you are attaching this volume to.
  • Select “Volumes” under “Elastic Block Store” on the left menu.
  • Click the blue “Create Volume” button at the top.
  • Set the desired size and then click the “Create” button.
  • Name the volume something appropriate like “Data Volume”.
  • Under “Actions” select “Attach Volume”.
  • Select the instance and click “Attach”.
  • ssh to the server.
  • Run dmesg to see if the volume has been attached.
  • Partition the volume:

    sudo fdisk /dev/xvdf
    p – check the current partition table to make sure you have the right disk
    n – create a new partition
    p – this is a primary partition
    1 – Partition number
    Accept the default first sector and size.
    p – to print and verify the partition table
    w – write the changes to the disk

  • Create the swap disk.
    sudo mkswap /dev/xvdf
  • Display available memory.
    free
  • Turn the swap on.
    sudo swapon /dev/xvdf
  • Check to see that the swap space has been activated.
    free
  • Set swap space to be activated automatically when the server boots.
    • Edit /etc/fstab:
      sudo nano /etc/fstab
    • Add the following entry at the bottom
      /dev/xvdf    swap    swap    defaults   0     0
      
  • Reboot and verify that the swap space has been activated.
    sudo reboot
    free

Leave a Reply

Your email address will not be published. Required fields are marked *