3 minutes read

POSTED Nov, 2020 dot IN Serverless

Frictionless Instrumentation with Lambda Layers

Suna Tarıyan

Written by Suna Tarıyan

Product Manager @Thundra


In many ways, serverless functions, like auto-scaling, pay-per-use, and reduced complexity, are great. When things go wrong and developers have a problem with their serverless architecture, they’re likely to check Amazon CloudWatch logs immediately to try to understand the issue. Although this method works perfectly for small-scale serverless architectures, logs fall short when your architecture grows to over 10-15 functions with an event-driven architecture. Application teams need end-to-end tracing to understand the overall behavior of the asynchronous architecture, and instrumentation comes to the rescue in enabling tracing. Fortunately, AWS has made instrumentation very easy with its layer support, announced at re:Invent 2018. In this blog post, we’ll explain in detail how AWS Lambda layers simplify instrumentation of serverless applications.

AWS Lambda Layers

AWS Lambda layers let you configure your Lambda functions by pulling new code in the form of layers. Using Lambda layers, you can easily include libraries to your Lambda functions without changing the source code and redeploying your function.

Developers can create their own Lambda layers that are defined as ZIP files or integrate with third-party applications like Thundra using ARN. Layers give you the flexibility to add code, data, images, or even new runtimes to your existing application. Let’s check out how you can use AWS Lambda layers to integrate with Thundra.

Thundra and Lambda Layers

Thundra offers you different ways to instrument Lambda functions. With a few lines of code, you can instrument your Lambda function, then take advantage of other tracing capabilities via environment variable configurations. With Thundra Lambda Layer, it’s much faster and easier.

When you use the Thundra layer, the layer version needs to match for each runtime. Thundra currently supports three runtimes: Node.js, Java, and Python.

You can add the Thundra layer on the Lambda Function configuration page by adding layer ARN of the matching runtime. In the following sections, we’ll take a deep dive into using AWS Lambda layers for instrumenting your serverless applications.


When you build a distributed application including serverless architecture, VMs, and containers, it’s important to track your transactions end-to-end. You can keep your system healthy and stable by staying aware of bottlenecks in your application.

In order to understand what’s going on in your serverless architecture, you need to instrument your Lambda functions. Instrumentation provides a deep level of observability, for example, by displaying transactions as a timeline view, including interacted resources.

Automated instrumentation is one way you can start to have this visibility. You don’t need to change any code, except for adding a Thundra Lambda layer and an APl key to instrument your functions. This will allow you to measure your Lambda code’s execution time. Thundra automatically instruments and traces AWS resources such as SNS, SQS, Kinesis, and third-party endpoints.

Serverless Framework Plugin

By using Thundra Lambda layers, you reduce the time you spend on instrumenting your functions for using Thundra’s core capabilities. Even so, if you have many Lambda functions, it is a little bit tiring to add Thundra Lambda Layer to each one. But there is a solution: Thundra’s Serverless Framework plugin instruments multiple functions at once.

If you're using Serverless Framework as an IaC platform to define and deploy your resources, you can easily add Thundra Lambda Layer to your project. You’ll just need to change the .yaml file of your project, and voilà! Thundra Lambda Layer is automatically added to your project, and you can monitor and trace your functions on Thundra.

You can instrument your Java, Python, and Node.js functions with Serverless Framework plugin.

Seamless Monitoring

Thundra’s Amazon CloudFormation integration helps you start to use Thundra within a couple of minutes and to monitor your Lambda functions. After CloudFormation integration, you can start to use Thundra for the functions you selected. However, Thundra’s core capabilities, such as tracing, displaying your Lambda function’s architecture view, or configuring security options, come with instrumentation.

As we mentioned in the previous section, to take advantage of these features, you can instrument your Lambda functions by adding the Lambda layer and API key environment variable. With seamless monitoring, you don’t need to go over this list. Instead, just click on the “Instrument” Lambda functions and see the magic. Now you can start to use Thundra’s core features.

Automated instrumentation from Thundra console

Figure 1: Automated instrumentation from Thundra console

At the backend of this seamless monitoring feature, we’re still using Thundra Lambda Layer. When you click on the “Instrument” button, Thundra adds the matching Thundra layer and API key to the Lambda configuration for you. 

Thundra does not change your function code, so you can easily un-instrument Lambda functions by using the Thundra console or deleting the Thundra layer from your Lambda function configuration.

You can use seamless monitoring for an AWS Lambda function if your account has Amazon CloudFormation integration enabled, and if the function’s runtime is Node.js, Java, or Python.

Seamless monitoring has one more capability specified for the Java functions: fast startup. Using Thundra’s custom runtime support, you can lower the cold-start overhead. It’s as easy as one-click instrumentation. After selecting the functions with Java runtime, just click on the “Instrument with Fast Startup” button and reduce the time it takes to initialize your Lambda functions.

Thundra Layers Gives You No-Effort Monitoring

Thundra uses AWS Lambda layers to monitor your functions and reduce the time it takes to instrument them. Thundra works even without instrumentation through layers, but its core features, such as distributed tracing and architecture overview, come with instrumentation via layers. In this article, we’ve covered the two most prominent ways of plugging layers into your serverless functions: you can either use the Serverless Framework to instrument multiple functions at once with IaC, or use instrumentation via the Thundra user interface with mouse clicks.