Starting up Amazon EC2

From HIO Wiki
Jump to: navigation, search

What is Amazon EC2

Amazon Elastic Compute Cloud (Amazon EC2) is a service that allows users to rent virtual computers. Amazon EC2 provides scalable computing capacity in the Amazon Web Services (AWS) cloud. Users will boot up their virtual machine (instance) using Amazon Machine Image. Amazon EC2 eliminates users'need to invest in hardware up front, development and deployment of applications would be faster. Amazon EC2 can launch as many virtual servers, configure security and networking, and manage storage. Amazon EC2 also enables scale up or down to handle changes in requirements or spikes in popularity, reducing forecast traffic. [1]


Set Up

Sign in to Amazon Web Services

  • Select EC2 Virtual Service
  • Click instance on the ES2 control panel and then click Launch Instance.

Launchinstance.PNG

  • Choose an Amazon Machine Image (AMI). For HIO project, choose Ubuntu Server 14.04 LTS:

AmazonAMI.PNG

  • Choose an Instance Type.

border = "1"

  • Click next. Go to Configure Instance Details, then assign subnet default range as us-west-2a. Subnet is where Amazon stores the data of the instance. Making sure that the data is stored close to the access point to increase the performance of the instance.

Subnet.PNG

  • Set up the Size to 30 Gib. For Free Tier, Amazon provides a maximum of 30Gib of data. It is possible to add additional volume to the instance later with extra cost per use.

Volume.PNG

  • After Configuration, Click Review and Launch located on the lower right.
  • Amazon will prompt user to create a new key pair or select an existing one.
This key pair (*.pem) will be the password file to connect to the instance.
  • To Connect an instance. Click Connect that is next to Launch Instance.
  • Follow the Instruction on using "A standalone SSH client" or "A Java SSH Client directly from browser (Java required)" in the prompt.

Connect to Instance Using Ubuntu

The quickest way to connect to the Linux Instance on Amazon EC2 is to use a Linux Operating system.

  • On the Instance Page, Click Connect
  • Under Example, Amazon generated a command for Linux Shell. Copy the Command
    • Make sure that .pem (Private key) file is located in the user home folder. Otherwise, the key location needs to specified.
  • Start Terminal, paste the ssh command that just copied, change instance name root into ubuntu
  • Select "yes" when prompt to connect the instance.

Connect to Amazon Linux Instance Using PuTTY

PuTTY is a free implementation of Telnet and SSH for Windows and Unix platforms, along with an xterm terminal emulator. It is written and maintained primarily by Simon Tatham. We will use PuTTY and PuTTYgen to connect to the Amazon EC2 instance. So, PuTTY is the emulator, and PuTTYgen will be used for key generation (the Amazon ".pem" file).

Generate Private Key with PuTTYgen
  1. Start PuTTYgen
  2. Under Type of key to generate, select SSH-2 RSA
  3. Click Load. Select the option to display files of all types
  4. Select the ".pem" file. Click Open. Click Ok
  5. Click Save private key to change the format from ".pem" to ".ppk".
  6. Specify the same name for the private key and PuTTYgen will automatically add the .ppk file extension.
Starting a PuTTY Session
  1. Start PuTTY
  2. In the Category Pane, select Session and complete the following fields:
    1. For Host Name box, enter ubuntu@public_dns_name. The public_dns_name can be found in Amazon EC2 Instances page. It is usually start with ec2-xx-xx... Copy the whole Public DNS and paste after the @ sign. For example, ubuntu@ec2-52-11-250-217.us-west-2.compute.amazonaws.com
    2. Under Connection type, Select SSH
    3. Make sure that the Port is 22.
  3. In the Category pane, expand Connection,expand SSH, and select Auth
    1. Click Browse
    2. Select the ".ppk" private key file that is generated from PuTTYgen. Click Open
    3. To use this session again later, save the session information by Select Session in the Category pane, enter a name for he session in Saved Sessions, Click Save.
    4. Open to start PuTTY session
  4. PuTTY will displays a security aleart dialog box that ask whether the connecting host is trustable for the first login session.
  5. Click Yes and the emulator window will appear.

Click here to find more information on how to start a PuTTY Session and Transferring Files

Hio-Yocto Project Requirement

Amazon EC2 Requirement to compile Hio-Yocto Project
CPU 2 Core Processors
Remaining Disk Size 30G

Amazon EC2 free tier provides a 1 Core processor with 30 Gib of volume. However, Hio project required at least 2 Core processors. The 30 Gib volume is barely enough to compile one image. To compile more image, it is required to create additional volume. To change the number of processor, users can choose different type of instance in the Create Instances interface.

AmazonEC2 Volumes

Other than the initial free 30G, Amazon provides users option to create their own volumes to match their needs. The volume is like a separate hard drive from the instance that can be mounted and unmounted from the instance.

To create Volume:
  • Expand Elastic Block Store
  • Click Volumes
  • Click Create Volume
    • Make sure that the Availability Zone match with the one in Instances
  • Click Create
To Attach the Volume into Ubuntu
  • Choose a Volume and click Actions (or simply right-click on the volume)
  • Select Attach Volume
  • Double click on Instance and select the instance that is running
  • Click Attach

After attaching the volume, input the following command into Terminal:

$lsblk

This command will show the name of volumes, the size, type, and where it is mounted to. In this example, sda and sdc are the name and they are partition into multiple parts. sda1 is mounted into the root folder. sdc1 and sdc2 are not mounted yet.
Lsblk.PNG

Mounting the Volume

New Volume from Amazon need to be formatted before using.

Note: Format the volume will erase the whole content if it has been used before.

To format, input the following command, replace <name of the volume> with the name of the newly created volume.

$sudo mkfs.ext4 /dev/<name of the volume>

Next, a directory needs to be created to attach the volume. Eg. we will create a directory calls /data in the root folder.

$sudo mkdir /data

Mount the volume into /data directory

$sudo mount /dev/<name of the volume> /data

check the mounted device

$df -h

Unmount the volume

to Unmount the follow from /data directory, input the following command

$sudo umount /dev/<name of the volume> /data

Note: Before detaching from instance, it is recommended to unmount the volume from the instance first to prevent lose of data.

File Transfer to Amazon EC2 Using FileZilla and SFTP

FileZilla is a GUI interface that allows users to transfer file between the host computer and the instance.

To install FileZilla, input the following command

$sudo apt-get install filezilla

To connect to Amazon Ec2

  • Edit > Setting > Connection > SFTP, and Click Add key file
  • Browse to the location of .pem and select it
  • A message box will appear asking to change the current .pem to .ppk format. Click Yes and select the location to store the .ppk file
  • (Optional) Select the generated .ppk file
  • Click Ok
  • Next step, Click File > Site Manager and Input the following parameters,
    • Host: public DNS name of EC2 instance
    • Protocol: SFTP
    • Logon Type: Normal
    • User: ubuntu
    • click Connect

Next Step : Setup Yocto Environment