visit
Not so long ago, a job requirement pushed me into the world of FaaS, and I was thrilled. I had dreams of abstraction — eliminating all that tedious work no developer likes doing. “We are not operations engineers!” I exclaimed proudly. “We should not need to dabble in the dark arts of the Linux Shell.”
But little did I know how wrong I was. We humans are creatures of habit, and one of my habits as an AWS user is checking the AWS Console religiously. It was my central place to monitor everything I needed to know about my servers’ health.Now comes the difficult question: How does monitoring work when using AWS Lambda and Serverless?
Note: I recently came across an awesome article on this topic by none other than the CTO of RisingStack, Peter Marton. He explained in detail how to do monitoring right. I urge you to take a peek, it will change your view on monitoring forever.
Excuse me…? Can I have some monitoring, please? But, without being a burden on my application. We’re lucky that, in our day and age, this is a given. Monitoring software has become so advanced that in today’s world of programming the overhead is minimal. The sun was not shining so bright back in the day. Monitoring applications was followed by a known fact that it would impact your app’s performance significantly.Developers are starting to view the Function as a Service architecture as a savior, something that makes it possible to scale applications automatically and serve only as many users as needed. The pay-as-you-go method cuts costs drastically and makes it possible for startups to create awesome software for a fraction of the cost.
But, wait a minute. What else needs to be cut for that to become a possibility? A couple of things come to mind. The overview of your code performance and tracking errors are first. Silent failures as well. How do you monitor the performance of a server that is not a server? Schrödinger’s server? Okay, now my head hurts. This paradox needs a new perspective. Monitoring Serverless is a new beast in itself. Traditional methods will not work. A new mindset is in order.server != functions
Instead of telling our functions to send along additional data with every invocation, why not just collect their residual data? This is a cool idea! It’s a known fact all AWS Lambda functions send their logs to AWS CloudWatch.
Opening up CloudWatch I can see the logs clearly. All the function invocations are listed.
The logs are extensive, the only issue is I can’t seem to make any sense of them. I can see the functions we’re invoked, but not much else. Error messages for failing functions are not verbose enough, so they often go unnoticed. I’m also having a hard time finding functions that timed out. I also tried logging through the command line. It shows possible errors a bit better, but still, not good enough to have peace of mind.
serverless logs -f my-function
Not to mention the tiresome nature of having to push code to AWS every time you’d want to try out something new. Thankfully, all is not lost.
Setting it up is surprisingly easy. Installing one npm module and adding a few lines to the serverless service’s serverless.yml and voila, API Gateway emulated locally to run Lambda functions.
Switching to the directory where I created the sample function and service, I just ran the following command in a terminal:npm install serverless-offline --save-dev
After installing serverless offline I just referenced it in the serverless.yml configuration:
serverless offline start
That’s it, a local development simulation of API Gateway and Lambda is up and running!
The was very straightforward. You just follow their instructions, , press a few next buttons, and everything will be hooked up automagically! They have a great .
If you want to know, the timer stopped at 4 minutes. I’m impressed. However, I’m much more impressed with . I can finally see what’s going on.Errors are highlighted, and I can see the overall health of my system. I feel great all of a sudden. It also tracks the cost so I don’t blow the budget. Even function tailing in real-time is included. Now that’s just cool!
In the last few months the Dashbird team have added loads of new features, including X-Ray support, creating projects, a new throughput based billing with a brand new free tier. I’m excited to see what’s next. With this watching my back I’d be comfortable with using Serverless for any large-scale application. The word relief comes to mind.
Hope you guys and girls enjoyed reading this as much as I enjoyed writing it. Until next time, be curious and have fun. Do you think this tutorial will be of help to someone? Do not hesitate to share. If you liked it, let me know in the comments below or give it some claps so more folks here on Medium will see it.
Tools:
Resources:
Originally published at .