Building Lambdas: Terraform vs Serverless.

Recently we have been creating a new application using Lambdas in AWS. The lambda is JavaScript interacting with APIs and S3 buckets.

We already have experience of using Terraform for cloud infrastructure provisioning and we had heard good things about Serverless, so we thought it would be interesting to compare both technologies.

We started with Terraform. We created a user in AWS with permissions for Cloudwatch, S3, API endpoints and Lambdas. Next we created a bucket to hold the Terraform state. Writing the Terraform code was relatively easy but very verbose. This can be overcome by using module abstraction to enable code reuse between projects. The Terraform error messages could be a bit cryptic at times, especially around role management. The other main issue seemed to be enabling logging with Cloudwatch, as this could have been more straighforward.

Next, we tried the same process but using Serverless. We created a user with extra cloud formation permissions and created a bucket to hold the Serverless state. The Serverless code was easy to write. The documentation was easy to follow and clear for the problem we were trying to solve. The main advantage was if things weren’t correct it was easy to check the generated cloud formation template to help understand the issue.

I would say the team preferred Serverless for the problem space we were working in. It felt a better fit for an application team wanting to focus more on the Lambda code than the infrastructure being provisioned. The main benefits were:

  • Faster to implement.
  • Easy configuration of Cloudwatch.
  • Ability to read the Cloudformation template generated
  • Role management was more automated for interaction between the Lambda, S3 bucket and API.
  • Built-in integration with Webpack allowed modern Javascript syntax in the Lambda code.

If you are interested in the POC code for a simplified version of the Lambda checkout and