Connect To Amazon EC2 via Putty


In this post I’m going to show how to establish a SSH connection to an Amazon EC2 instance using Putty using a Windows box. First of all we need to download following tool. It can be find under the section called For Windows on Intel x86.

Step 1: Generating the Private Key using Puttygen

In Amazon AWS environment each instance (EC2, RDS, ElasticCache, etc…) is attached to a permission/security group, access to each service is provided through Private Key/Public Key authentication. Each Amazon EC2 instance will holds the Public Key of the permission/security group it belongs. To connecting to a specific Amazon EC2 instance need to use the corresponding Private Key (xxx.pem). Puttygen can be used to generate the local Private key out from the Private Key obtained from Amazon AWS required for establishing the connecting to Amazon EC2 instance via Putty.

Open Puttygen as shown in Figure 1 and click Load to select the Private Key obtained form the Amazon AWS.

 Generate private key

Figure 1: Selecting the Amazon AWS Private Key

Next click Save private key, next click OK on the appearing dialog box as shown in Figure 2 and 3

Saving generate private key

Figure 2: Saving the generated Private Key

Provide a suitable name (eg: aws_putty_private_key.ppk) for the newly created Private key, make sure to store all these keys in a well secure place.

Saving generate private key

Figure 3: Saving the generated Private Key

Step 2: Pointing the generated Private key to Putty

Now we have finish creating the private key required by Putty. Open Putty and navigates to Connection -> SSH -> Auth from the left pane of the Putty window as shown in Figure 4. Select the newly created private key (aws_putty_private_key.ppk) from the Options controlling SSH authentication pane as shown in Figure 5

Options controlling SSH authentication

Figure 4: Options controlling SSH authentication

Selecting the generated private key

Figure 5: Selecting the generated Private key

Step 3: Providing Amazon AWS EC2 instance information

Navigates to Session from the left pane of the Putty window as shown in Figure 6 and Provide the Host Name or the IP of the Amazon EC2 instance Connection Type as SSH.

Providing Amazon AWS EC2 instance information

Figure 6: Providing Amazon AWS EC2 instance information

Step 4: Connecting to Amazon AWS EC2 instance

Provides the User name of the EC2 instance.

Connecting to Amazon AWS EC2 instance

Upon successful authentication connection is established. Happy hacking.

Connecting to Amazon AWS EC2 instance

Advertisements

Monitoring and Managing Amazon RDS Databases using MySQL Workbench


Last couple of week I was looking for an easier approch to manage the Databases created on Amazon RDS instances. I had to run through a tedious set of steps in carrying out routine stuff like introducing new updates, taking daily backups and moving it to an Amazon S3 bucket, etc… Before getting into touch with MySQL Workbench had to run through several intermediate hops (Connect to one of the EC2 instance via SSH and connect to the RDS instance from there, ;-( ) even to run a small query on the tables.

Let me eleborate the step I followed in setting up the connect with the DB created on a Amazon RDS instance.

Step 1: Launch MySQL Workbench

Launch MySQL Workbench and select New Server Instance found under Server Administration section form the Welcome screen as shown in Figure 1.

MySQl Workbench Welcome Screen

Figure 1: MySQl Workbench Welcome Screen

Step 2: Specify Host Machine of the Database server

Next form the Create New Server Instance Profile wizard, provide the Public DNS of the Amazon EC2 instance under Remote Host as shown in Figure 2 (this EC2 instance will be as the intermediate point to access DB that resides inside the Amazon RDS instance). To find the Public DNS specific to the EC2 instance can be done as illustrated in Figure 3. Click Next button to procced.
Specify Host Machine

Figure 2: Specify Host Machine of the Database screen

Amazon EC2 Instance

Figure 3: Amazon EC2 admin console screen

Step 3: Creating the DB connection

Fill in the values as described below which illustrated in Figure 4.

  • Connection Name – Provide a name to identify your connection
  • Connection Method – Select Standard TCP/IP over SSH from the drop down list instead of Standard(TCP/IP). Then on the appearing two tabbed pane, fill the following values found under Parameters tab.
    • SSH Hostname – Provide the Public DNS of the Amazon EC2 instace (refer Figure 3) which will be used as the intermediate server instance used to create the connection with the DB instance.
    • SSH Username – Provide the user of the Amazon EC2 instance (refer Figure 3) which will be used as the intermediate server instance used to create the connection with the DB instance.
    • SSH Key File – Provide the Private Key (xxx.pem) used to connect Amazon EC2 instace via SSH
    • MySQL Hostname – Provide the Endpoint of the DB instance created in Amazon RDS(refer Figure 5).
    • Username – Provide the Master Username of the DB instance created in Amazon RDS(refer Figure 5).
    • Password – Click on Store in Keychain.. button and type the password provided while creating the DB instance in Amazon RDS.

Click Next button to procced.

Database Connection

Figure 4: Database Connection screen

Amazon RDS DB Instance

Figure 5: Amazon RDS DB Instance

Step 4: Testing the Database Connection

In this step it validates the parameters provided in the previous step and upon success it returns Database connection tested successfully(refer Figure 6). Upon this message the Next button get activate to procceds to Management and OS.

Test DB Connection

Figure 6: Testing the Database Connection

Step 5: Management and OS

Select SSH login based management option and select the appropriate parameters for Operating System, MySQL Installation Type (refer Figure 7).

Management and OS

Figure 7: Specify remote management type and target operating system

Step 6: Setting up remote SSH Configuration

Provide the following parameters

  • Host Name – Provide the Public DNS of the Amazon EC2 instace (refer Figure 3) which will be used as the intermediate server instance used to create the connection with the DB instance.
  • User Name – Provide the user of the Amazon EC2 instance (refer Figure 3) which will be used as the intermediate server instance used to create the connection with the DB instance.
  • Select Authenticate Using SSH Key and provide the SSH Private Key Path – Provide the Private Key (xxx.pem) used to connect Amazon EC2 instace via SSH

Remote SSH Configuration

Figure 8: Remote SSH Configuration

Step 7: Test Host Machine Settings

In this step it validates the parameters provided in the previous step and upon success it returns Testing host machine setting is done(refer Figure 9). Upon this message the Next button get activate and clicking Next buttin it popup Review Settings dialog box (refer Figure 10).

Test Host Machine Settings

Figure 9: Test Host Machine Settings

Review Settings

Figure 10: Review Settings

Step 8: Creating the Instance Profile

Provide a name for the Profile got created.

Creating the Instance Profile

Figure 11: Creating the Instance Profile

Step 9: Done

Success

Figure 12: Workbench Home screen with the new profile

Amazon s3 with Codeignitor


When selecting the deployment environment as Amazon AWS, it comes up with a nice tool called Amazon S3 (Amazon Simple Storage Service) which can be used as a storage for static content, especially as a content delivery network (CDN).

Amazon S3 provides a simple web services interface that can be used to store and retrieve any amount of data, at any time, from anywhere on the web, and it also consists with a set of APIs to manipulate it via most of the popular programming laguages.

In our project we maintained a separate server, accessed via FTP to store all the images used in the application. The application was developed on top of CI framework, so we didn’t had any problem communicating with the FTP server since the framework itself was geared with a feature rich FTP library. Amazon AWS environment was selected as the hosting environment. With the introduction of Amazon AWS environment we opted to use Amazon S3 as our image repositiry for the project. I found an Amazon S3 PHP library developed for CI on Git Hub. Later extended it to suite our requirements. It can be downloaded over here.