Django application and AWS ELB health checks

When deploying a Django application to an EC2 instance (or ECS, etc) that is behind an Elastic Load Balancer you will run into some issues with the ELB health checks. They way a health check works is that a certain url path is checked by the ELB, if the application returns HTTP code 200 the application is marked as healthy.

The problem is that your Django application will be configured with a number of  ALLOWED_HOSTS  that determine on what hostnames Django will ‘answer’. Off course, the ELB health checks won’t use your configured hostname but will be visiting the EC2 instance’s IP address.

By adding the snippet below we can query the AWS instance metadata and get the local IPv4 address, which we add to the  ALLOWED_HOSTS  setting.


Switching from Macbook Pro to Linux powered Thinkpad T470p

This morning I received my T470p I ordered as a replacement for my aging Macbook Pro. I have been on the looking for a couple of months now since it became clear Pro is not exactly for professionals anymore in the Apple product line.

After customizing various models on the Lenovo website I settled for the T470p. I really needed more than 32Gb RAM and a good CPU so I ordered the maxed out T470p. Waiting was hell, especially since my order came 3 weeks later than initially estimated :/

But today was the day (UPS said it would be tomorrow but it got here today, so a nice suprise!). After booting a Fedora 27 live cd all looked good: everything worked as I wanted and the installation went without a hickup. No need to disable secureboot, change any BIOS options (I did enable VT-X but that is unrelated to Linux installation / functioning) or had to fiddNewle with anything to get a perfectly usable laptop.

I’ve been a thinkpad user some years back but for various reasons I switched over to Mac OS for some time. Coming back to the trackpoint was a really good feeling 🙂 So far the biggest problem has been adjusting to a new keyboard layout and shortcuts.

The HiDPI scaling is too much for me at 200%, 100% is better but Gnome / Wayland really needs a 150%/125% option.

Since I’ve only had this machine since this morning I can’t really comment on battery usage or long term use yet. Should anything come up or if anyone has questions I’ll get more updates here.

The specs

  • Intel i7-7700HQ
  • 14″ WHQD (2560×1440) IPS non-touch
  • 32 GB DDR4
  • Nvidia GeForce 940MX
  • 512GB NVMe SSD

S3Uploader: Simple S3 upload script

For a project of mine I needed a simple script or application to upload files to an Amazon S3 bucket. I couldn’t quickly find something that scratched my itch so I wrote  a simple application called S3Uploader.

Using S3Uploader is very simple, once you have your S3 bucket and credentials configured, simply install the application using

and you can start uploading files to your bucket, for example

The code is quite simple and is actually very suitable or a beginner to learn from. You can check it out the code from the source repository on BitBucket and the PyPi package page.

Diving into the code

The most interesting bit, the actual uploading of a file happens in the s3uploader.uploader module:

It’s a very simple class that takes a path to a file and uploads it to the S3 bucket. The interesting bit here is at the beginning of the store_file method where we extract the filename from the path using the os.path.basename function.

Another interesting piece of code can be found in the s3uploader.main module where we use the argparse module to process arguments.

Creating an ArgumentParser is quite easy using the following code (bits have een removed from the original source for clarity)

The  action='store_true' flag changes our argument parsing so the parameter acts as a flag instead of variable. The bucket parameter requires a variable and the –verbose parameter gives a true or false value.

The  nargs='+'  on the file parameter enables the user to pass multiple values for our file parameter.

We can process the parameters from argparse like so

Interesting parts here is the change from the parameter name store-paths to store_paths and the fact that the file parameter is an iterable due to the nargs='+'  option.

This little application was a quick and dirty job and can be improved. I’ll save that for a later time and try and write more about it if it’s interesting.

The learning revolution

It’s been some time since the media reported about MOOCs or other online / new studying platforms. In case you haven’t been following, MOOC stands for Massive Open Online Course. With the rise of the internet and the democratization of knowledge a new frontier was breached: specialised courses are no longer restricted to universities, schools or commercial training centers. Now it is possible to learn new skills from experienced instructors in an online course, in real time, with fellow students from around the world!

But as things go on the internet, yesterdays hype is todays old news. And the same applies for MOOCs. New technology has enabled anyone to create and share video courses that have been made available at an extremely low cost and sometimes even free.

The MOOC courses of yesterday would cost you anywhere from € 10,00 to a couple of hundred euros. But platforms such as PluralSight, Lynda or TutsPlus are available at a monthly subscription cost. This cost lies somewhere around € 20,00 a month and offers you access to a course library that offers you thousands (yes, 1000’s) of courses.

I have been using PluralSight for some time now and have been really happy with the quality of the courses and the content that is available.