Essential Open Source Serverless Code Libraries

Home Blog Essential Open Source Serverless Code Libraries
open source serverless code libraries main

Serverless applications, due to their distributed nature, are often stuck having to reinvent the wheel. 

While small utility scripts and functions are often easily instrumented and monitored, anything of a transactional nature will need to implement special code to provide developers with common tools like stack traces, atomicity, and other patterns that rely on a singular flow of control.

Implementing these same tools for every new serverless application can quickly grow tedious, and prove to be error-prone as the software evolves. 

In this article we’ll explore some open-source serverless libraries that help solve many of these challenges. Leveraging these tools will give your developers the information they need to quickly troubleshoot, diagnose, and resolve any failures in your serverless application.

The first post in our open source serverless series covers our pick of the essential tools. Read it here

Common Problems in Serverless Development

While serverless applications have a number of benefits over traditional microservice-oriented approaches, these advantages come at the cost of complexity in implementation and maintenance. Many pain points are introduced when the infrastructure running your code has a limited lifespan. Some of these include:

  • Traceability – As your serverless functions only exist for a short time in production, troubleshooting side effects can be problematic when things go wrong
  • Bloated libraries – With limits on execution time, any touchpoint that your code hits should be directly related to the task you are performing, and these should be as efficient as possible. Some language ecosystems complicate this by introducing dependencies that can increase the size of your functions, slowing down execution through excessive indirection.
  • Emulating production hardware – As the specific characteristics of AWS Lambda execution containers include a number of restrictions on software installed and user security roles, emulating production hardware as closely as possible in development is critical to ensuring code behaves similarly in both environments.
  • Single responsibility – Standard practice for developers is to focus on having each part of the codebase do one thing, and do it well. Defining this correctly will have a direct correlation with the size and complexity of your serverless functions.

Library 1: aioboto3

One issue of serverless applications is that the temporary nature of the hardware makes control flow management a critical component of your architecture. This involves implementing systems that communicate with AWS services like S3 in a method that can emulate a synchronous call without relying upon continuous call context. In addition, many of these services have their own security, configuration, and communication requirements, resulting in a lot of code duplication across functions as you integrate each service into your larger architecture. 

aioboto3 is a python package designed to address this concern. It combines the time-saving AWS SDK Boto 3 with aiobotocore, allowing your serverless functions to seamlessly and quickly communicate with other AWS services in an asynchronous fashion, abstracting away the attendant complexity of tracking the activity and execution across a dynamic architecture. Using aioboto3, you can asynchronously call S3, EC2, and many other services with a single line of application code and some configuration. This will allow your serverless application to behave more responsively, while giving you a means to track and maintain data integrity.

Library 2: DAZN Lambda Powertools

Serverless applications require bootstrapping specific tooling for each new collection of functions and service interactions. This includes having to read and forward based on correlation IDs, emitting and tracking logs when Lambda functions time out, and implementing security measures like obfuscation. While it’s possible to implement each of these services as the need arises, unless your application has very specific needs there is not going to be much of a difference between configurations for each application.

DAZN Lambda Powertools – a project of Lumigo Developer Advocate Yan Cui – is a powerful collection of tools, middleware, helper libraries, and AWS clients that ease the headaches of building serverless functions in AWS Lambda. While not a traditional SDK, DAZN Lambda Powertools combines multiple useful auxiliary applications, templates, utility functions, and general support middleware into a single interface that can be maintained through configuration stored alongside your application. This lets you quickly implement common tasks in your Lambda functions, speeding the development process and reducing the duplication of effort and complications to maintainability you’d encounter developing these solutions in-house.

Library 3: Lambda API

Jeremy Daly, as a well-known serverless advocate, built Lambda API to provide a lightweight application development framework for AWS Lambda functions. It is a javascript API built to mirror common frameworks like Express.js and Fastify, but without the attendant dependencies and inefficiencies these libraries bring with them when working in a serverless context. Lambda API allows your developers to write serverless applications in a more familiar manner, abstracting away the complexity of HTTP communication, asynchronous execution, and deployment through familiar code constructs while removing the bloated dependencies that drive the more common javascript APIs – Express.js, for example, has 30 dependencies included upon deployment. While Fastify improves on this at 17, neither can hold a candle to Lambda API, which features 0 dependencies.

Library 4: AWS Serverless Express

AWS Serverless Express, similar to Lambda API, is a framework focused on giving your developers the tools they need to develop in familiar patterns that may not be strictly applicable to the canonical concept of a serverless function. It’s built to run your Node.js application in a serverless context, with built-in Express.js support to ensure your developers are as productive building their REST APIs serverlessly as they are when building traditional microservice applications. Simply add a few proxies in API Gateway, and your application is up and running in AWS Lambda.

Conclusion

As serverless technology matures, so do the development pipelines and processes that surround it. While serverless function platforms like AWS Lambda are powerful tools that revolutionize application development when scaling functionality, the nature of how serverless platforms operate introduces many unique challenges that would not be present in a traditional web application. 

The open-source nature of serverless technology has given rise to a robust ecosystem of plugins, templates, and various tools that can prove critical in building a maintainable and dependable serverless toolchain. 

Building upon these, many open-source developers are releasing frameworks and libraries that solve many of the various pain points of serverless development. You’ll find that by adopting some of these tools, you can quickly add familiar components to your serverless application, giving you the tools you need to quickly release and iterate on your application.

Run serverless with confidence! Start monitoring with Lumigo today - try it free