AWS Lambda: Log early, Log often, Log EVERYTHING

In the world of building client/server applications logs are important.  They are helpful when trying to see what is going on in your application.  I have always held the belief  that your logs need to be detailed enough to allow you to determine the WHAT and WHERE without even looking at the code.

But lets be honest, in most cases when building client/server applications logs are an afterthought.  Often this is because you can pretty easily (in most cases) debug your application and step through the code.

When building a serverless applications with technologies like AWS Lambda functions (holds true for Azure Functions as well) your logging game really needs to step up.

The reason for this is that you cannot really debug your Lambda in the wild (you can to some degree locally with AWS SAM or the Serverless framework).  Because of this you need produce detailed enough logs to allow you to easily determine the WHAT and WHERE.

When I build my serverless functions I have a few guidelines I follow

  1. Info Log calls to methods, output argument data (make sure no PII/PHI)
  2. Error Log any failures (in try/catch or .catch for promises)
  3. Debug Log any critical decision points
  4. Info Log exit calls at top level methods

I also like to setup a simple and consistent format for my logs.  The example I follow for my Lambda logs is as seen below

timestamp: [logLevel] : [Class.Method] - message {data points} 

I have found that if I follow these general guidelines the pain of determine failure points in serverless environments is heavily reduced.

Till next time,

2 thoughts on “AWS Lambda: Log early, Log often, Log EVERYTHING

  1. Pingback: Interesting links of the week (03/05 – 03/11, 2018) – same stuff, different day

  2. Pingback: Log Early, Log Often… Saved my butt today – Maintainer of Code, pusher of bits…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s