Saturday, October 8, 2011

Web Application on AWS using Python, Part Two

This is the second part of my experience with Python/Django and AWS. This assignment was from a potential employer, so I wanted to do it quick. I just jumped in without doing any reading.

To begin with, I had no idea that Amazon provided ssh access to the EC2 environments. I used Google AppEngine earlier and it doesn't provide ssh access. And it was not apparent from EC2's Python Developer Center page. As I said, I didn't do any reading.

There were just two tutorial pages, I started with the first and midway through it dawned me that that tutorial used EC2 and RDS alright, but the app was still going to run on my laptop. Just my database was goin to be on AWS instead of local.

I moved on to the second tutorial. It asked to install boto, a Python interface, on my laptop, using which I would be able to manage EC2 and RDS instances. It also asked to install fabric, which would allow me to perform sysadmin tasks on EC2, right from my laptop.

I wrote python scripts to create EC2 and RDS (MySQL) instances. Just used the ubuntu machine image suggested in the tutorial. Created and setup security key pairs to access AWS services. Got the virtual host name and wrote scripts to install python/django on it. Configured security allowing my IP address access EC2 and RDS. In the end I could run my laptop app pointing at the RDS database.

Don't remember when and how, I figured out I could just ssh into EC2. I used putty for this, regenerated key pairs using putty, although it was not really necessary.

The next challenge was connecting Python/Django app to the MySQL RDS. Again I needed the connector module. I tried downloading and installing but it just wouldn't work and I didn't want to spend much time. After searching on the web, I found the BitNami Django stack machine image (ami-3d34f654) was available on AWS. I created an instance, this time using AWS console. Okay, now how do I login into the new instance? Login attempts were just failing. Took some time to figure out that the user id was "bitnami". On the previous instance, it was "ubuntu". Anyways, I am grateful to BitNami, they will get my business someday.

Last hurdle and it took the longest of time: everything setup - Python, Django, MySQL RDS, my app. I start Django, but just can't access the app from my browser. What the ...? Took a long time and figured out that when I start the server, I need to pass the virtual host name as a parameter. How do you guess that?
In the end, my Python/Django app was up and running on Amazon Cloud. I didn't build each and every functionality of the news site. In fact built just the basics. I sent a note to the employer about this. Two days later I sent another note saying I did not want to pursue the position.

No comments:

Post a Comment