Well,
this is embarrassing. I spent most of today chasing a problem that I
just couldn’t get my head around. The issue: my Go lambda function did
not log anything I printed from log.Print()
(or various variations) in AWS CloudWatch.
I
checked the permissions, and everything looked just fine. The LogGroup
was created, and I did find other logging from the lambda in the
CloudWatch logs, but not one that should come from any log.Print()
statement.
I even posted a question on StackOverflow, which basically means that I am completely out of ideas, as it is my last resort. I wasn’t expecting an answer quickly, so I kept digging. I deployed a second lambda, completely stripped from anything useful, except log.Print()
.
I deployed the function, and started it from the AWS console. Lo and behold, there was logging from log.Print()
in CloudWatch! I upped the ante a little bit, by adding a line that prints a JSON.stringify
’d
version of an object. I redeployed, and…. No change! WHAT!? I’d changed
the source code of my Lambda function, but nothing changed in the
output after deploying to AWS? That’s when it started to dawn on me…
I have written lambdas for AWS almost exclusively in Node.js, and with Node.js, you just upload the source and AWS will take care of the rest. Not so much with Go. Go is a compiled language, and in stead of uploading the source code, you upload a binary.
You see where this is going. I forgot to run make
before deploying my lambda!! I deployed the same binary time and again, even though I’d changed the source. So, I ran make
and deployed to AWS, and there was my logging, finally! Pretty lame,
but I’m sure I’ll laugh about it in a couple of years. Or decades. You
can see why I chose the ‘double facepalm’ image to accompany this post…
I’ve updated my Makefile
to add a command install
,
which builds-then-deploys my lambda. If only someone had asked me ‘Did
you perhaps forget to push?’ That would’ve got me thinking in the right
direction.
Given the embarrassing nature of this issue, you might wonder why I chose to write about it at all. It’s simple really. Despite having a lot of experience writing software, I still make silly mistakes. Sure enough, I’m fallible just like the next person.
Also, when you’re learning a new language (or anything new, really, it’s not limited to programming), you’re bound to make mistakes. In fact, that’s when the learning takes place. I’ve been trying to teach myself how to make “latte art” for almost two years now (without taking a barista course), and despite having a few successes, I still mostly suck at it. I’m learning though, and that’s what matters.
Making mistakes is okay, don’t let anyone tell you otherwise. The alternative is to never learn anything new. How sad would that be?