Introducing Lambda Tools: a new framework for deployment to AWS Lambda

This post is more than 7 years old.

Posted at 08:00 on 16 November 2017

Lambda Tools is a new project that I've been working on over the past few weeks or so. It is a build and deployment toolkit, written in Python, to make it easier to work with AWS Lambda functions. It started out as a user story in our backlog at work but since then it's grown into a full blown open source project with a life of its own.

The "serverless" model offered by AWS Lambda is a useful and potentially cost-effective one, especially for scheduled tasks that only need to run every so often and don't require a lot of resources. The "free tier" doesn't expire at the end of your initial twelve month trial, which is an added bonus.

The downside is that it can be tricky to work with. If your function requires additional libraries, it starts to get a bit more complex, and if any of these are written partly in C and require special compilation, things can get pretty messy. On top of that, you will want to write unit tests for your functions and set up some sort of Continuous Delivery pipeline for them.

Lambda Tools includes several features to make these things easier. For example, it gives you an option to build your function in a Docker container to avoid these messy "invalid ELF header" errors. You configure it simply by creating a YAML file called aws-lambda.yml, which might look like this for example:

version: 1
 
functions:
  hello_world:
    runtime: python3.6
    build:
      source: src/hello_world
      requirements:
        - file: requirements.txt
 
    deploy:
      handler: hello.handler
      role: service-role/NONTF-lambda
 
      description: A basic Hello World handler
      memory_size: 128
      package: build/hello_world.zip
      region: eu-west-2
      timeout: 60
 
      tags:
        Account: Marketing
        Application: Newsletters

Here are some of the other ideas that I'm thinking of implementing for it:

  • A unit test runner
  • Support for Python 2.7
  • Support for languages other than Python (.NET, Node.js, and so on)
  • Integration with Terraform:
    • The ability to plug it into Terraform's external data source provider
    • The ability to read configuration from stdin
    • A scaffolding engine to generate Terraform modules on the fly
  • Integration with triggers such as CloudWatch cron jobs, API Gateway, and so on
  • A full-blown sample application
  • The ability to include or exclude specific files when building your package

At the moment it only supports Python 3.6 but nevertheless it is in a usable state. You can install it using pip install lambda_tools and it includes full instructions in the readme file on the GitHub repository. Additionally, if you're interested in getting involved with its development, feel free to fork the project and send me a pull request or three. If it's anything more complex, raise a ticket on the GitHub issue tracker and we'll chat about it there.