Monday, May 7, 2018

AWS exposes route tables so I can recover from their bug

The cloud.  It is a wondrous thing.  When it works.
But I think that one thing that most all can agree on, it should 'just work'.  All aspects of your cloud experience should 'just work'.

In the past weeks I have shifted my attention to AWS. 
It has taken some time to get used to referring to a virtual network under the marketing term Virtual Private Cloud. Or a virtual machine as an 'EC2 instance' or any number of other marketing term focused things.
My preference here, call it what it is, not the marketing name for the feature.
Enough of that.

Back to the title.  One of the first things that I thought interesting with AWS is that within a VPC, the route table is exposed to me.
Why would I want to / need to muck around with a route table in the cloud?  I have port level firewalls rules (Security Groups), I have to stand up an Internet Gateway to enable outgoing traffic.  Why would I ever need to muck with something as low level as a route table?

Well, I can tell you from being burned on this multiple times now, it is so I can fix what the AWS portal screws up for me.

Back to my original statement - this is the cloud, it should 'just work'.  Networking is a pretty fundamental thing here.  It needs to be solid, resilient, and always functional.
But yet, at least three times now, in less than three months I have lost days due to multiple route table entries in a VPC that I created through the portal.

And usually the kicker is that one of the route table entries is correct and there is a second one that is empty.  A route table entry, but no defined route.

The really strange things happen when things work say manually or with one VM, and then you start automating and suddenly what you automate does not work.
As if one deployment uses the correct route table and the other doesn't.

It is one of those obscure things, that as a customer, I expect to work - all the time.  I should not have to think about this, I should not have to remember (in the recovery from frustration) that I had been burned by this in the past and go looking, only to discover that I have this strange named but empty route table entry.

My call to AWS, fix it.  Don't let it be mucked up in the first place.  Give me success here.  Don't frustrate me, don't waste my time.

But then, you did get paid for extra days of running compute while i tried to figure it all out.  So I guess that you might not have my interest at heart.

Thursday, January 4, 2018

Finding likes between two arrays

In a recent interview I was asked to write a function to sole the following problem:

You have a SQL query and two arrays, find the like elements between the two arrays.

(I am assuming that a few of you have your own opinions on how to solve this, and that is excellent - please enlighten me)

The first thought that popped into my head was that this was not a coding interview, the second was that i really needed a laptop to work through this, and the third was - doesn't PowerShell have a cmdlet that will do this for me?

Back at home, I thought I would investigate the PowerShell angle.  Since I had access to a laptop.
I am assuming a small dataset

First, lets build a couple arrays to validate with:

$array1 = "Elmer", "hunter", "Bugs", "rabbit", "Tweety", "bird", "Sylvester", "feline"
$array2 = "Eddie", "investigator", "Roger", "rabbit", "Jessica", "rabbit", "Judge", "doom", "tweety", "bird"

Now, I did add some variation for fun.  Because why might this be an important skill?
It might be important because I might need to mine a bunch of data or logs to investigate a pattern.

At this point I have arbitrarily added an additional requirement on myself; I want to see all of the matched data items, not just the matched values.  Equivalents vs. equals if you will.
Why? Again, in an investigation I will probably want to use a fuzzy match instead of a literal match.  And then I will want to work through the resulting set again.  (most likely both with eyes and with code).

In regards to PowerShell doing this for me, I discovered this:

$compared = Compare-Object -ReferenceObject $array1 -DifferenceObject $array2 -IncludeEqual

But when looking at the output, working with this is not very intuitive and it hides my fuzzy match and detail output.

PS C:\Users\Brian> $compared

InputObject  SideIndicator
-----------  -------------
rabbit       ==
Tweety       ==
bird         ==
Eddie        =>
investigator =>
Roger        =>
Jessica      =>
rabbit       =>
Judge        =>
doom         =>
Elmer        <=
hunter       <=
Bugs         <=
Sylvester    <=
feline       <=

I actually ended up going back to my original idea; 

$likes = @()

foreach ($element1 in $array1){
    foreach ($element2 in $array2){
        if ($element1 -like $element2){
            $likes += $element1;
            $likes += $element2;
        }
    }
}

while not highly efficient and I am sure not wonderful with large data sets, it does give me the results that I wanted for further analysis:

PS C:\Users\Brian> $likes
rabbit
rabbit
rabbit
rabbit
Tweety
tweety
bird
bird

It is easy to see from this output where I might want to go next; counts, deeper analysis, trends, etc.  It all depends on the details in the records used.

If you have different ideas that meet my requirements, please share.