2.1 Choosing an AMI
2.2 Key Pair
2.3 Instance Address
Getting Started with Amazon EC2
AbstractThe goal of this assignment is to introduce you to the Amazon Cloud Service. You will set up a new EC2 instance, run it, connect to it via SSH, and execute a simple python script on it.
Launching an Instance
Choosing an AMIGo to the AWS Management Console page, and sign in. Once you are signed in, click on EC2. From the top right menu right next to where your name appears choose US East (N. Virginia). You’ll see a prominent button that says Launch Instance. Click it.
Next you will be prompted to select an operating system for your virtual server. For this assignment, we’re going to use the basic 64-bit Amazon Linux AMI 2014.09.2 (AMI Id: ami-146e2a7c). Choose the t2.micro instance type, then click "Review and Launch". In the
The next window lets you review details about the ami you chose. Click on "Launch".
Key PairYou will be prompt to Select and existing key pair or create a new key pair, which allows you to generate a public/private key combination for connecting to your instances, or use a key pair you already created. Generate a key and save it to your local computer; we’ll use this key in a short while to log into the instance we’ve just created.
After downloading the key pair, click on "Launch Instances," and then on "view instances."
Instance AddressYou will need wither the public address or the Public IP of the instance in order to connect to it. To obtain the public address/IP for your instance, go to the Instances page, select your running instance, and scroll down to the bottom of the page. The address is in the Public DNS/IP field.
Logging Into Your InstanceClick on Instances on your EC2 Dashboard, and you should see your instance running. The question now is: how do you log into it?
Either follow the steps bellow or see this tutorial.
Open Instance for ConnectionsEC2 lets us establish an SSH connection from the Unix
sshshell command or Windows SSH client such as PuTTY. Before we can do this however, you need to configure your instance to open up connections on port 22. This is done by opening up port 22 on the default security group. Click "Security Groups" on the left hand side on the EC2 Web page, and select default. Click on the "Inbound" tab. To add support for SSH, select "SSH" in the drop-down box. For source (IP or group), add 0.0.0.0/0 (Note: the rule may already exist; if so, then move to the following section).
One cannot establish SSH connection from a desktop computer within the university network. Only
lvsis open for such connections. So, if you wish to do this task from the university you first have to log into
ssh linuxUserName@lvs.cs.bgu.ac.il(replace linuxUserName with your university linux username) and then perform the Unix connection. The Windows connection is only doable from home.
UnixConnecting via Unix is simple, the recommended way. To connect, you will need the EC2 key pair you created and downloaded earlier. Just save the key file in the same directory you are going to run the ssh command from, and simply enter the following command at the shell:
ssh -i <key-file> ec2-user@<instance-address or IP>
ssh -i my_key.pem email@example.com
WindowsTo log in to our instance using PuTTY, we have to use our EC2 key pair. However, Putty won’t work directly with the keys that EC2 generated for us. Fortunately, we can download PuTTYGen to convert our .pem key file into a format that PuTTY can process. Once you’ve downloaded PuTTYGen, click "File"->"Load Private Key" to load the .pem file. Then click "Save Private Key" to save a .ppk file that can be used by PuTTY.
In PuTTY, we can select this .ppk file in the "Connection"->"SSH"->"Auth" menu to use it as our private key to login to our EC2 instance (Note: the file needs to be read-only). Select "browse" and choose the .ppk file you've just generated. Next choose "Session" on your left.
Use the instance public address or IP in the Host Name or IP field on PuTTY’s Terminal login screen. When prompted for a username, enter
ec2-user. PuTTY will use your private key to log you in to your instance (If you gave a pass phrase when converting the key, you will be asked to enter it).
Running a Command in PythonRun python by typing python in the shell, then type:
print "Hello, World!"
It should print:
Hello, World!. Press ctrl-d to exit python.