A Comparison of Serverless, SAM, CloudFormation, and Terraform
Alex Thornton, Software Engineer
Infrastructure as Code (IaC) is a powerful tool for managing cloud resources, especially in serverless environments like AWS Lambdas. In this post, we’ll explore the four most popular IaC tools for Lambdas: Serverless Framework, AWS Serverless Application Model (SAM), AWS CloudFormation, and Terraform.
Throughout this article, we will be ranking the various technologies on a 0-10 scale across the following six areas:
Ease of Use: The tool’s user-friendliness and simplicity, including the ease of understanding and working with its configuration language, availability of helpful documentation and tutorials, and the learning curve for beginners.
Integration with AWS: The tool’s ability to work seamlessly with AWS’s services, specifically its ability to manage lambda functions and related resources effectively.
Community Support: The level of community engagement and support surrounding the tool, including the size and activity of the user community and the availability of online forums and communities for troubleshooting and knowledge sharing.
Testing and Debugging Capabilities: The tool’s capacity for effectively testing and debugging infrastructure configurations and Lambda functions, such as automated testing frameworks, support for local development and testing, and ease of troubleshooting and diagnosing issues during development and deployment.
Portability and Cloud Agnostics: The tool’s ability to work across various cloud platforms and manage multiple environments. It considers factors such as the ease of migrating infrastructure configurations between environments and cloud providers, as well as the tool’s ability to manage an application architecture that requires resources across multiple platforms.
Flexibility and Customizability: The tool’s flexibility in accommodating diverse requirements and customizations, including the ability to define complex infrastructure setups, support for advanced configuration options, and extensibility through plugins or extensions.
The Serverless Framework
The Serverless Framework is a popular open-source framework designed to facilitate the building and deployment of serverless applications across a wide range of cloud providers, including AWS. It simplifies the process of defining Lambda functions and their associated resources, allowing developers to abstract away many low-level details and get started quickly.
The framework has some limitations:
As the name may imply, it primarily focuses on provisioning serverless resources, making it less than ideal for more complex project architectures.
While it is compatible with AWS, it is not natively integrated with the platform, making managing resources and troubleshooting issues more challenging, especially compared to tools like AWS CloudFormation and SAM.
Despite these limitations, the Serverless Framework remains an excellent choice for smaller projects and less experienced AWS developers, as it offers an extra layer of abstraction that simplifies the development process. The following graph represents how this framework stacks up on the six evaluation areas.
Graph 1: Serverless Framework Evaluation
AWS Serverless Application Model
The AWS Serverless Application Model (SAM) provides an alternative solution for managing infrastructure as code (IaC) for Lambdas. This toolkit, developed by AWS specifically for building serverless applications on their platform, provides a user-friendly syntax for defining Lambda functions and other serverless resources, similar to the Serverless Framework.
Unlike the Serverless Framework, SAM is compatible only with AWS and cannot be used to manage resources on other cloud providers. One of the main advantages of using SAM is that it allows for local testing and debugging of Lambda functions. The `sam local` command line tool enables developers to test Lambda functions with sample event data and see the output without having to deploy the application to the cloud. Moreover, developers can step through their code line-by-line, set breakpoints, and examine variables using sam local, which makes it easier to identify and fix issues with the code. This feature is handy for testing Lambdas locally before deployment. While SAM primarily focuses on serverless architectures, it is built on top of CloudFormation and fully supports using non-serverless CloudFormation resources. The following graph shows our evaluation of SAM against the six functional areas.
Graph 2: Serverless Application Model Evaluation
AWS CloudFormation is a service that allows you to create, update, and delete AWS resources in a predictable and repeatable manner. CloudFormation offers a comprehensive and powerful way to manage IaC for Lambdas and nearly every other AWS resource, and it is natively integrated with AWS, making it a top choice for infrastructure management in that environment.
Unlike some previously mentioned tools, CloudFormation does not abstract any low-level details. You must be far more verbose when defining a lambda or any infrastructure. While CloudFormation’s lack of abstraction may impose a steeper learning curve than other IaC tools, it grants developers complete control over every configuration parameter, allowing for precise and granular resource management. As a result, CloudFormation is best suited for larger, more complex projects that require a higher level of customization and control over the AWS resources being used. When including resources outside of Lambda or other serverless components, consideration should be given to the lifecycle of the various parts of the IaC. That discussion, however, is outside of the scope of this blog. The following graph represents our evaluation of CloudFormation’s capabilities.
Graph 3: AWS CloudFormation Evaluation
Terraform is a third-party abstraction language for IaC that can be used with multiple cloud vendors. While Terraform’s cloud-agnostic approach and versatility make it an attractive choice for managing IaC across numerous cloud providers, it does come with some limitations when working with AWS.
Terraform’s AWS provider can sometimes lag behind AWS updates, meaning it may not immediately support the latest AWS features. This can frustrate developers who need to integrate new AWS features into their infrastructure quickly. Additionally, because Terraform doesn’t natively integrate with AWS, it may not provide the same level of integration and automation as AWS-native tools like CloudFormation and SAM. This can make it more challenging to manage and troubleshoot complex infrastructure that relies heavily on AWS-specific features. Despite these limitations, Terraform remains a popular choice for managing IaC, particularly for teams managing infrastructure across multiple cloud providers. Its modular and reusable code, version control integration, and powerful templating language make it a flexible tool for managing complex infrastructure. The following is our evaluation of Terraform.
Graph 4: Terraform Evaluation
In conclusion, Infrastructure as Code (IaC) tools are essential for managing AWS Lambdas and their associated resources in a predictable and repeatable manner. Each tool has its own strengths and weaknesses, making it best suited for different use cases.
Serverless Framework is ideal for getting started quickly and for small-scale serverless applications, as it abstracts away many low-level details of working with Lambdas. SAM is best suited for AWS-centric serverless applications, as it provides a simple and easy-to-use syntax for defining Lambda functions and resources and allows for local testing and debugging. CloudFormation is ideal for managing more complex serverless applications and other AWS resources, as it provides a comprehensive and powerful way to manage IaC, though it requires a steeper learning curve. Terraform is cloud-agnostic and can manage resources across different cloud providers, making it a good choice for organizations with multi-cloud environments.
Ultimately, the choice of IaC tool will depend on your organization’s specific needs and requirements. However, by using these tools, you can simplify managing, updating, and troubleshooting your Lambdas and associated resources while ensuring a reliable and scalable infrastructure.
Graph 5: Overall IaC Capability Comparison