Sergey Nivens - Fotolia
SAM Local enables offline development for serverless apps
Serverless computing is a draw for developers, though hybrid functionality has been limited. AWS' SAM Local now enables local testing of Lambda functions -- but faces competition.
Iterative development is a common app dev methodology -- write some code, test it, make sure it works and then add more code. And new services like SAM Local give iterative development a boost.
Agile-minded developers often write lots of unit tests to validate that chunks of code operate as expected, but there are some things unit tests can't verify. For example, a developer might need to visually verify the placement of an input box or see the colors on a webpage to modify them.
Offline development is not always possible with AWS Lambda, the cloud provider's serverless computing service. Developers typically need to write code to test even the most minor changes. And complex frameworks add another several minutes when they must compile, upload and verify changes.
Imagine if when you hit Save to back up a file, you had to wait 10 minutes before you could continue writing. How often would you save? You probably would wait until you're almost completely finished.
The same is true for developers. If it takes 10 minutes to see a change, they won't deploy changes or test out small batches of code. This means developers will be far less likely to experiment with different options.
Take Lambda local
Last year, Amazon rolled out AWS Serverless Application Model (SAM), a framework that allows developers to deploy serverless applications that run on AWS Lambda and Amazon API Gateway. Developers can build a simple specification on their local system that defines a stack -- connections between API Gateway HTTP events and the Lambda functions that execute them. SAM creates and manages the necessary resources and connects API Gateway to Lambda.
Under the hood, SAM creates an AWS CloudFormation stack, which allows developers to use a simplified template language and then translate it to CloudFormation. This process is similar to Serverless Framework, except it's specifically designed for Lambda.
AWS received a lot of attention from developers who were tired of waiting several minutes to test small changes to code. A new service called SAM Local enables them to build and test applications locally with the familiar SAM tool.
Now, in addition to using the SAM command-line tool to build and deploy applications, developers can test this code using the command sam local. This command runs a Docker server and spins up an emulator to simulate API Gateway and Lambda on the developer's local system. When combined with an offline database, like DynamoDB Local, developers can build serverless apps when they're offline. It also means developers can make changes and experiment with new features much faster than with traditional serverless development methods.
Options for serverless on premises
Any developer that used SAM to deploy serverless applications can now develop code offline and then deploy to CloudFormation. Developers new to the service might also choose SAM Local, but Serverless Framework has numerous advantages over SAM.
Serverless Framework included offline testing long before SAM Local arrived. Serverless Framework also has local execution and emulation through Serverless Offline, which works in a similar way to SAM Local. It runs a Docker instance and emulates API Gateway and Lambda. Additionally, Serverless Framework supports other platforms, unlike SAM Local.
Still, SAM Local shows that AWS recognized the need for local developer tools, which means developers can expect more future support from AWS. And the service does offer a few advantages that a Serverless Framework team might benefit from, such as template validation. Both systems use Node.js and support API Gateway and Lambda, but neither currently supports DynamoDB execution.
SAM Local's potential
The release of SAM Local is not a reason to dump Serverless Framework, nor is it a reason to completely rethink a serverless architecture. But developers building new applications should give SAM Local serious consideration and weigh the pros and cons of using a tool officially supported by Amazon over a multiplatform framework.
Neither Serverless Framework nor SAM Local enables complete offline development without additional work. Developers must wire in special code to detect and handle offline applications, which triggers local execution instead of targeting AWS resources, such as Lambda functions or DynamoDB tables. Still, SAM Local gives Amazon a unique opportunity; it could modify its AWS software development kits to handle connections to DynamoDB Local, which would dramatically improve the offline development experience.
Don't struggle to deploy serverless architectures
Let Lambda bring serverless to your enterprise
It's not all good when using Lambda