Exploring the cloud with AWS Free Tier (2)

In the first part of this “diary” I found a cloud provider for my developer’s testing needs – Amazon’s AWS. This time we will mention some hiccups one may encounter when doing some basic operations around their EC2 instance. Finally, we will prepare some Docker image for ourselves, although this is not really AWS specific – at least not in our basic scenario case.

Shut it down!

When you shutdown your desktop computer, you see what it does. I’ve been running Windows for some years although being a Linux guy before (blame gaming and music home recording). On servers, no doubt, I prefer Linux every time. But I honestly don’t remember what happens if I enter shutdown now command without further options.

If I see the computer going on and on although my OS is down already, I just turn it off and remember to use -h switch the next time. But when “my computer” runs far away and only some dashboard shows what is happening, you simply don’t know for sure. There is no room for “mechanical sympathy”.

Long story short – always use shutdown now -h on your AMI instance if you really want to stop it. Of course, check instance’s Shutdown Behavior setup – by default it’s Stop and that’s probably what you want (Terminate would delete the instance altogether). With magical -h you’ll soon see that the state of the instance goes through stopping to stopped – without it it just hangs there running, but not really reachable.

Watch those volumes

When you shut down your EC2 instances they will stop taking any “instance-hours”. On the other hand, if you spin up 100 t2.micro instances and run them for an hour, you’ll spend 100 of your 750 limit for a month. It’s easy to understand this way of “spending”.

However, volumes (disk space for your EC2 instance) work a bit differently. They are reserved for you and they are billed for all the time you have them available – whether the instance runs or not. Also, how much of it you really use is NOT important. Your reserved space (typically 8 GiB for t2.micro instance if you use defaults) is what counts. Two sleeping instances for the whole month would not hit the limit, but three would – and 4 GiB above 20GiB/month would be billed to you (depending on the time you are above limit as well).

In any case, Billing Management Console is your friend here and AWS definitely provides you with all the necessary data to see where you are with your usage.

Back to Docker

I wanted to play with Docker before I decided to couple it with cloud exploration. AWS provides so called EC2 Container Service (ECS) to give you more power when managing containers, but today we will not go there. We will create Docker image manually right on our EC2 instance. I’d rather take baby steps than skip some “maturity levels” without understanding the basics.

When I want to “deploy” a Java application in a container, I want to create some Java base image for it first. So let’s connect to our EC2 instance and do it.

Java 32-bit base image

Let’s create our base image for Java applications first. Create a dir (any name will do, but something like java-base sounds reasonable) and this Dockerfile in it:

FROM ubuntu:14.04
MAINTAINER virgo47

# We want WGET in any case
RUN apt-get -qqy install wget

# For 32-bit Java we need to enable 32-bit binaries
RUN dpkg --add-architecture i386
RUN apt-get -qqy update
RUN apt-get -qqy install libc6:i386 libncurses5:i386 libstdc++6:i386

ENV HOME /root

# Install 32-bit JAVA
WORKDIR $HOME
RUN wget -q --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebac kup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u60-b27/jdk-8u60-linux-i586.tar.gz
RUN tar xzf jdk-8u60-linux-i586.tar.gz
ENV JAVA_HOME $HOME/jdk1.8.0_60
ENV PATH $JAVA_HOME/bin:$PATH

Then to build it (you must be in the directory with Dockerfile):

$ docker build -t virgo47/jaba .

Jaba stands for “java base”. And to test it:

$ docker run -ti virgo47/jaba
root@46d1b8156c7c:~# java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) Client VM (build 25.60-b23, mixed mode)
root@46d1b8156c7c:~# exit

My application image

Now I want to run my HelloWorld application in that base image. That means creating another image based on virgo47/jaba. Create another directory (myapp) and the following Dockerfile:

FROM virgo47/jaba
MAINTAINER virgo47

WORKDIR /root/
COPY HelloWorld.java ./
RUN javac HelloWorld.java
CMD java HelloWorld

Easy enough, but before we can build it we need that HelloWorld.java too. I guess anybody can do it, but for the sake of completeness:

public class HelloWorld {
        public static void main(String... args) {
                System.out.println("Hello, world!");
        }
}

Now let’s build it:

$ docker build -t virgo47/myapp .

And to test it:

$ docker run -ti virgo47/myapp
Hello, world!

So it actually works! But we should probably deliver JAR file directly into the image build and not compiling it during the build. Can we automate it? Sure we can, but maybe in another post.

To wrap up…

I hope I’ll get to Amazon’s ECS later, because the things above are working, are kinda Docker(file) practice, but they definitely are not for real world. You may at least run it all from your local machine as a combination of scp/ssh, instead of creating Dockerfiles and other sources on the remote machine – because that doesn’t make sense, of course. We need to build Docker image as part of our build process, publish it somewhere and just download it to the target environment. But let’s get away from Docker and back to AWS.

In the meantime one big AWS event occurred – AWS re:Invent 2015. I have to admit I wasn’t aware of this at all until now, I just got email notifications about the event and the keynotes as an AWS user. I am aware of other conferences, I’m happy enough to attend some European Sun TechDays (how I miss those :-)), TheServerSide Java Symposiums (miss those too) and one DEVOXX – but just judging from the videos, the re:Invent was really mind-blowing.

I don’t know what more to say, so I’m over and out for now. It will probably take me another couple of weeks to get more of concrete impressions about AWS, but I plan to add the third part – hopefully again loosely coupled to Docker.

Personal Log (2): Leaving Linux, buying guitars

Not that I write continuation of the personal log every time Federer wins a Slam title, but after dramatic final of the Wimbledon it really happened. (Just another instant classic after last year final? :-)) Fifteen and counting so it seems.

I wanted to confess that I stopped using Linux on my computers. I still have out of date Ubuntu on my desktop, but I can’t remember last time I used it. I went for Windows XP after all those Linux years, because I play more games now than ever. Video and music processing is also better supported on Windows – more software to choose from, VST support, etc. Seriously, why to use Wine just to pretend I’m not using Windows, right? Of course – anytime I have to work in command line in Windows, it’s real pain in the ass. When I changed my old computer at work for Lenovo T500 (with some troubles though) I decided to go for Windows XP only and in order to have some Linux I searched for some virtual machine solution. Friend of mine recommended VirtualBox and I was satisfied! It worked nicely, there was some trick with virtual folder name (try different name then the directory name if you have problem, or something like that ;-)), but after just a few hours I had nice Ubuntu machine for development tasks that required Unix tools, strong command line and all the rest you don’t have in Windows for free. Of course, performance was… virtual. 🙂 But if you want to try some virtual machine software, I strongly recommend this one. Documentation is OK, not too much to drown in and I found everything important there.

What I can’t understand is SVN Tortoise client. It’s absolutely great tool, looks nice, integrates to contextual menus for files, etc. So far so good. But when you want to check modified files to find out what is not added to repository (and should be) or when you want to commit, the view shows you either only managed files or all files recursively – there is no way that non-managed directory is just reported without the complete sub-tree. Compare this to default CLI functionality of the svn st command. Man I miss that so much! But not that much that I plan to setup my system PATH and run the all-time-loser “cmd” to use it.

There is one more thing I dislike on Windows. I alt-tab a lot, I’m of those erratic guys. 🙂 And sometimes I alt-shift-tab back too. Sometimes, when I depress these keys in a wrong order, Windows is strongly convinced I wanted to switch the keyboard layout (alt-shift). Trouble is, there is limited amount of options (keyboard shortcuts) to do so, this one is clearly the best. I should probably download some tool just do switch between keyboard layouts. Slovak keyboard is not good for coding really. Enough Windows rant for now.

I bought a new guitar! I have infamous Behringer’s V-Tone pack – because it was cheap and I was young(er) and uninformed when I bought it. The price was good, amplifier is good, guitar is… well, it’s some kind of Strat and it is possible to play on it. Now I know there are better options in the same price tag (not too many though), but what’s done is done. To have at least semi-decent guitar I bought French LAG AM100:


Black beauty!

It looks cool, it’s Superstrat, it is something different than the Strat, so I might actually also learn more about guitars per se. It was priced 356€ but in a massive sale action I acquired it for 156€, why not? I actually didn’t know what to buy as I also wanted some Ovation, but I decided to buy the best value from whatever I wanted. Funny sale strategy when you learn prices only on site. 🙂 Even before I bought it I had started to learn some scales and other stuff to enhance my play. Chords, rhythm, no problem, but I wanted to go on after a long stagnation – and with better guitar it’s even more fun!

Is the guitar good? More people claim it’s a good value even for the original price, so I guess I wasn’t wrong with my buy. Quality is OK, but I honestly can’t judge guitar when I can’t compare it. Maybe later I’ll write more on the guitar, trouble with LAG is that they have no official English site (as a manufacturer, not as reseller), forums are dominated by French language, no real documentation for newbies like me. So I have to rely on other forums, other people and learn the rest by myself. Of course, when I just play on it, there is no problem, but you know… when you have a new toy, you want to play with it even more. Tune it (later probably, and I don’t mean just strings now), understand it. However, enough for this time – I need to practice!