AWS CLI inhuman output and what I suggest

The problem

If you use AWS you probably use AWS CLI. This tool gives you control over your resources from the command line. AWS CLI can output the results of your commands in several formats. None of the formats seem to be useful for humans.

AWS CLI can output the data in the following formats:

  1. JSON, the default – good for processing with jq or programming languages, definitely not good for a human looking at list of few or more instances.
  2. text – good for processing with command line tools such as awk, very hard to read for a human.
  3. table – WTF? Probably meant for humans. Cluttered and difficult for a human to process. See the screenshot:
awscli-din
AWS CLI. List of instances. –output table. Is it for humans?

You can make it look better but what you see above is in no way reasonable default and making it look prettier should not be as unpleasing as described in the user guide towards the end of the page.

My takes on solving this

Take 1 – old script

I have a script which uses outdated Ruby AWS client which does not work with eu-central regions because it’s old. It was originally built for EC2 classic so it fails to show VPC security groups.

oldscript

If newer regions and VPC security groups issues are solved this is a fine tool for human output.

Take 2 – JQ

While the old script is not fixes I have this temporary solution: jq transformation of AWS CLI output JSON (from my .bashrc_aws). The output is one line per instance.

DESC () 
{ 
    aws ec2 describe-instances | jq -r '.Reservations[].Instances[] | "\(.InstanceId)%\(.KeyName)%\(.PublicIpAddress)%\(.LaunchTime)%\(.InstanceType)%\(.State.Name)%\(.Tags)"' | sed 's/.000Z//g' | column -t -s '%'
}

It works well when there are no tags or small amount of tags per instance. With few tags on an instance, the line becomes too long and wraps. Reformatting sample output here for your convenience. Original is one logical line, wrapped, takes almost two lines in the terminal window.

i-XXXXXXXX  KEY_NAME  52.XXXXXXXXXX   INSTANCE_START_TIME  t2.small
running
[{"Key":"rollback-who","Value":"new"},
 {"Key":"Name","Value":"XXXXXXXXXX/132-1-7"},
 {"Key":"creator","Value":"deploy"},
 {"Key":"env","Value":"prod"},
 {"Key":"role","Value":"XXXXXXXXXX"},
 {"Key":"rollback-id","Value":"XXXXXXXXXXXXXXXXXXXXXXXX"},
 {"Key":"status","Value":"Live"}]

Take 3 – ec2din.ngs

This is one of the demo scripts in the NGS project that I’m working on.

The column after state (“running”) is the key name.

ec2din-ngs
ec2din.ngs – human output

It would be better if actual available screen width would be considered so there would be no need to arbitrary trim security groups’ names and tags’ keys and values (the ... in the screenshot above).

How I think it should be solved

NGS (the new shell I’m working on) implements the Table type which is used to do the layout you see on “ec2din.ngs – human output” screenshot. Table is part of the standard library in NGS. As you see, it’s already useful in it’s current state. There is plenty of room for improvement and the plan is to continue improving Table beyond simply “useful”.

This is the right direction with the following advantages:

  1. The script that needs to output a table (for example ec2din.ngs) does not deal with it’s layout at all, making it smaller and more focused on the data.
  2. The script can set defaults but does not handle which columns are actually displayed and in which order. The Table type handles it using another NGS facility: config which currently gets the configuration from environment variables but should be able to read it from files and maybe other sources in future.
  3. Output of tabular data is a very common task so factoring it out to a library has all the advantages of code deduplication.

I would also like the shell to automatically detect heuristically or otherwise which data comes out of the programs that you run and display accordingly. Most of the data that is manipulated in shells is tabular and could be displayed appropriately, roughly as ec2din.ngs displays it. Maybe ec2din.ngs will become unnecessary one day.

In my dream, the output is semantic so that the shell knows what’s on the screen and allows you to navigate for example to i-xxxxx part, press a key and choose which operation you would like to perform on the instance. When you pick an operation, the shell constructs a command for such operation and executes it exactly as if you typed it in (so it’s in history and all other CLI advantages over GUI apply).

Common Sense Movement – where is it?

brain-605603_960_720

Let’s look at systems and software engineering.

We hear about all kinds of “cool” methodologies, ideas, frameworks: DevOps, Scrum, Agile, Kanban, Continuous Integration, Continuous Delivery, Puppet, Chef, Ansible … and combinations of these.

Why do you hear about all this cool stuff all the time? Why there are hypes all the time? Simple: money. Another hype, another opportunity to sell you something [at higher price]: products, support, certifications, guidance. You don’t necessarily need these things but they definitely would like to sell you all of it.

I’m starting Common Sense Movement

This humorous thought crossed my mind yesterday. You know, just to balance the situation a bit. Then I realized why don’t you hear much about the shiny cool “common sense” methodology: money.

You can’t sell a “common sense” certificate. That’s because if someone really has some common sense, he/she is not going to pay you for this crap and the only certificate you can sell would be “Failed Common Sense Practitioner”. Actually I doubt you can  hardly sell any crap to common sense practitioners. That’s a problem. So, there is no Common Sense Movement for you 😦

I really would like the hype waves to stop so we could just do our work in peace. Meanwhile, when you are approached by a client or a boss with yet another “We need tool X” or “We need technology Y” you should really answer with “Prove that you need it and it’s optimal usage for our money and time considering other alternatives” no matter how new,shiny or cool that thing is.

Prove your tool is the right choice

I see two common approaches at work when it comes to choosing tools.

Photo of different tools
How do you choose?

Bad

I have heard about this new shiny cool framework/library/tool, let’s use it!

It might be a good approach when you want to learn something in your spare time, just don’t do this at work.

Good

We have this problem and found a few alternative solutions (frameworks/libraries/tools) that might solve it. We will investigate and see if any of them fit our needs.

Note that depending on your situation, it might be the case when none of the existing tools will be a good fit for your project.

It might be tempting to look at existing solutions in a positive light thinking “our problem is not unique, there are tools solving it already”. The problem might appear to be similar to the problems that these tools solve but remember to look and focus and what’s unique to your circumstances.

Suggested approach

You should prove that the points below are wrong.  Assume that the tool you are evaluating:

  1. Does not cover your needs.
  2. Has crappy/new/unstable code.
  3. Has no community so getting answers to your questions or help is a nightmare.
  4. Has none or very costly official support.
  5. It will have a steep learning curve.
  6. It will be harder to maintain than any other alternative or your own code.
  7. You will need to modify the tool and it will be tough.
  8. Provides so little that it’s not worth another external dependency.
  9. Will cause lock-in with very high switching costs. (You can affect this one to some degree with your design).
  10. Has big company behind it which
    1. had huge investment and only cares about things like ROI and market share and not you, even if they did at some point in the past.
    2. has more interesting markets than you and optimizes the product for these markets, making it not a good fit for your situation.
    3. generates hype making it all look rosy even when the product has grave flaws.
    4. makes it look like everybody uses this tool.
    5. makes it feel like the next best thing.
  11. Has a big alliance behind it with many interests of different partners with zero intersection with your interests.
  12. Most places that use this tool suffer immensely but either don’t talk about it or you don’t hear that for other reasons. Dig deeper to find such information.

Calling some friends and asking them about the tool is very good but note that your situation is different so most of the points listed above still stand.

I guess that when you start positively when evaluating a tool, you might fall into the confirmation bias trap. Beware!

Winning executives team

0df763b

Brought to you by most trendy positions. You may recognize some of them at your work. Say hello!

  1. VP Downtime
  2. VP Broken Builds
  3. VP Lost Leads
  4. VP Ugly Sites
  5. VP Mediocrity and Disempowering
  6. VP Over-Complication Because it’s Cool
  7. VP of Sales Prevention
  8. VP of Successful Penetration
  9. VP Wrong Solutions
  10. Project Failure Architect
  11. Chief Titles Manager
  12. Chief Hype Evangelist
  13. Chief External Dependencies Promoter
  14. Chief Next Trendy Language Adopter
  15. Chief Instances Killer
  16. Chief Budget Overrun Manager
  17. Chief Miscommunication Advocate
  18. Chief Technical Debt Accumulation Promoter
  19. New shiny technologies Team Leader
  20. Misused Frameworks Manager

Some of the entries were contributed by VPs from beame.io

You are very welcome to extend this list in your comments.

Don’t call me DevOps

… unless you are ready to clarify what exactly do you mean by “DevOps”, I suggest you shut up don’t use that word at all.

The reason not to call a person “DevOps” is that DevOps seems to be a set of principles but not a person nor a job position. None of the amorphous definitions say it’s a person or position so don’t call DevOps anyone please.

Here is why I don’t recommend using this term at all:

  1. There is no exact definition. I’ve asked several people from in the industry and none of them could define the term precisely.
  2. Some people think that using specific tools is being DevOps. Some don’t. I don’t. Specific tools can not be used all the time as situations are different.
  3. Wikipedia has a description which I’m not sure can be used as a definition because some people would agree and some won’t.
  4. New Relic guys write “First, let’s just say there is no definitive answer.” in the article What is DevOps?.
  5. Automation seems to be one of the principles. Does it mean that an unsuspecting person that automates processes is now suddenly practicing DevOps? Are we just naming existing practices with a new fancy term now?

OpenStack is not ready

If you read the news you get the impression that OpenStack is the answer to anything (along with Docker but that’s for another post). I would like to balance this hype a bit. This post is my personal opinion.

tl;dr – TCO much higher than expected

When I first started working with OpenStack few years ago numerous issues caused me to mentally summarize “Not ready for production, re-visit in a year or two”. Unfortunately this still stands in 2016.

If you are considering OpenStack for your private cloud, think twice. Here are some examples of what I experienced few years back till now with two different clients that use OpenStack.

  1. Using API is a suffer
    1. API is inconsistent between components like Nova and Neutron so you will have more code.
    2. Neutron documentation for Python client is ridiculous: create network and list networks. That’s all. This is in contrast to the counterpart Nova documentation which is OK.
  2. Few years ago I have edited instance types (“flavors”) using the web UI. Somehow it screwed up all the types. Unfortunately I don’t know if there was an open issue for that.
  3. About a year ago we had production system workaround with a line of bash that would do internal ping within the message bus that OpenStack uses. Without this it would randomly get stuck and not respond to any management commands (create/delete instance for example). If I remember correctly this bug was fixed in Juno or Kilo, unfortunately I can’t find it.

Be sure to visit the bugs lists before your decision.

The Go language TL;DR review

I took a few hours to overview the Go language to make up my mind. Posting here because someone else might also find this useful.

Please note that I just reviewed the language. I did not write big chunks of code so my experience is fairly limited.

  • Compiled.
  • Easy to use almost as any high-level interpreted language, this is not a fiction, works as advertised. Simplicity and ease of use – goal checked.
  • Good libraries (HTTP client+server, FastCGI server, JSON, RPC, …)
  • VIM support in the code repo (syntax, indentation, …)
  • bash completion support in the code repo
  • The language as a whole makes the impression that the right choices were made.
  • It’s pragmatic.
  • It’s minimalistic for the capabilities it provides.
  • The only “big” innovation I see (besides the ease of use) is simplifying interfaces in a statically typed language. All other features resemble things I’ve seen somewhere else already. Actually “familiarity” of the language was one of the goals.
  • Has low level stuff, see http://golang.org/pkg/syscall/ for example.
  • As of this moment the Go language became my second favorite moving down JS and Python. Sorry, Lisp still remains the first. This of course might be a temporary condition till I start writing some real code. I hope it’s not.

Webkit background image wrapping bug

Context: I am doing a mobile web project for one of my clients.

Problem screenshot

WebKit wrapping bug screenshot (zoom)
Android Browser: background image is wrapped. Red arrow shows the height of the DIV.

Problem description

When using DIV with background image that is the same height as the DIV and top pixels of the background image are transparent, with repeat-x (or no repeat) there is an observable line at the top of the div painted with the color of the bottom pixel of the image.

Suspected buggy mechanism

I suppose it’s subpixel smoothing. Because of the observed facts:

  • The additional lines is less than a pixel wide as seen when zooming
  • Pixels affect colors of neighbours pixels

Suggested solution

  • Add two pixels at the bottom of the background image: one of the same color as the last pixel and one transparent. For example, if original image is from top to bottom (transparent,…,transparent,red,green,blue) it should become (transparent,…,transparent,red,green,blue,blue,transparent).
  • Keep the DIV vertical size the same as the original background: the two new pixels should be “rendered” outside the DIV.

Initially I’ve added only the transparent pixel at the very bottom but it interacted badly with both the last visible pixel and the contents of the div (not shown in the example, for simplicity).

I have created a Gist that shows the problem and the suggested solution. The Gist also includes the half-solution of only adding one pixel. For your convenience I have also uploaded the HTML of the problem and the suggested solution to this blog.

Additional info

  • On some devices, when going to landscape mode, the line disappears and is only observable when zooming in

P.S.
I learned something the hard way but I hope you will find this post and it will save you something from 1 to 5 hours of work.

RDS restore from dump time

Doing recovery test for one of my clients. I think recovery times might be useful to not-so-general public 🙂

TLDR version

.sql.gz file size: 829M
DB size after restoring: 6.2G
RDS instance: db.m1.small, MySQL 5.5.20, 50G, us-east-1b, not Multi-AZ.
Recovery tests date: 2012-08-14
Network: MySQL client in same AZ
Instance provisioning time: 8 minutes
Dump loading time: 58 minutes

More info

RDS parameter group: default.mysql5.5

RDS backups configuration: 35 days of backups

Restore command: time pv X.2.sql.gz | gunzip | mysql X

Restore command exact times:

real 57m35.001s
user 2m27.085s
sys 0m22.113s

Backup command: mysqldump --add-drop-table --add-locks --create-options --create-options --extended-insert --single-transaction --quick

Backup time: about 28 minutes.

Client: m1.small

Load on client when restoring: about 0.01, above 90% CPU idle.

Tables sizes info after recovery: SELECT data_length / 1024 / 1024 as "data", index_length / 1024 / 1024 as "index" FROM information_schema.TABLES where table_schema = 'MASKED' :

+---------------+---------------+
| data          | index         |
+---------------+---------------+
|    0.01562500 |    0.03125000 |
|    0.01562500 |    0.01562500 |
|    0.01562500 |    0.00000000 |
|    0.01562500 |    0.00000000 |
|    0.01562500 |    0.00000000 |
|    0.01562500 |    0.01562500 |
|    0.01562500 |    0.01562500 |
|    0.01562500 |    0.00000000 |
|    0.00000000 |    0.00000000 |
|    3.51562500 |    0.00000000 |
|    0.01562500 |    0.04687500 |
|    0.01562500 |    0.03125000 |
|    0.01562500 |    0.01562500 |
|    0.01562500 |    0.01562500 |
|    0.19713211 |    0.01269531 |
|    0.20276260 |    0.04687500 |
|    0.01562500 |    0.00000000 |
|    0.12012100 |    0.03613281 |
|    0.00007629 |    0.00195313 |
|    0.01562500 |    0.00000000 |
|    1.51562500 |    1.51562500 |
| 2053.00000000 | 1946.00000000 |
|   28.56250000 |   31.09375000 |
|    0.01562500 |    0.00000000 |
|    0.26562500 |    0.12500000 |
|    0.01562500 |    0.01562500 |
|    0.00000000 |    0.00000000 |
|    0.00000000 |    0.00000000 |
|    0.00000000 |    0.00195313 |
|   12.56250000 |    0.00000000 |
|    0.34375000 |    0.00000000 |
|    0.46875000 |    0.00000000 |
|    0.01562500 |    0.00000000 |
| 2139.00000000 |    0.00000000 |
+---------------+---------------+

Graphs from AWS RDS console

Screenshots were taken few minutes after restore finished.

HTH, Ilya.

Stop thinking, start doing.

Backgound

I could not find a “todo” software that would staisfy my needs so I decided to create one. The decision was also backed up by the fact that my good friend, Guy Egozy, was also very frustrated by the existing solutions.

The story

I started thinking about my “todo” software that I wanted to create. What it should include, how it should behave, etc… I was thinking for months. The important part is to realize when thinking becomes mental masturbation. Yes it is fun but it’s not productive. I admit I was slow to recognize the situation. When I did, I decided to start writing the code. It was a throw-away code, a protoype. When I had something that worked, I finally understood the following advantages:

  1. You learn a lot when implementing. No thinking + reading + analyzing will take you there. Of course you should but don’t over-do it.
  2. It’s much easiear to collaborate on. I can tell my friend all day about what I think but showing working application is a totally different story. Also he was finally able to participate by adding more code. Which he does till this day. (Thanks!)
  3. Makes possible to get any meaningful feedback from people, possible feature users.
  4. And of course you make steps toward the goal of having a good working version of the application (which we named Tagoholic), something you can share with the world, after few throw away versions.

Conclusion

Stop thinking, start doing — it’s way more productive.

P.S.

We are still working on Tagoholic. Collaboration (sharing) and mobile version are the two top requested features that are not there yet. We will let you know via Twitter when these are ready.