I’ve been using the Serverless Framework for around 2 years now. I not only use it for deploying Lambda functions and APIs, complete sets of infrastructure too and prefer it to AWS’ SAM. Although under the hood it mostly uses CloudFormation (like SAM), the way it orchestrates packaging of code for Lambda, then joining the dots automatically for API Gateway (and other event sources) makes deploying serverless applications incredibly simple.
More recently, AWS has been making waves with Amplify, which has made deploying applications end to end very simple by asking what you want to do, such as adding hosting or authentication, without needing to worry about the how part. I was excited to see Serverless release “Components”, as it looks to make some of the more complex or custom parts of deploying infrastructure simpler by building for use cases, and in some ways could be considered as a basic competitor to Amplify.
There are currently several components available, with the ability to build your own, but let’s take a look at something relatively common — deploying a website to S3 and CloudFront. Before serverless components, I would have to add custom resources to my template, which looked similar to below:
Even after 71 lines of code you still need to have created a certificate in ACM, built your react app, and then deployed it to the S3 bucket. The same thing using the new serverless components looks like this:
With components, we can create the same infrastructure in around 6 lines, 92% less! It even creates our certificate, builds and deploys our web application as well. If you were to take it another step further, you can deploy DynamoDB databases in just a few lines or a RESTful API as well, which brings me to my next point — Serverless says:
While in Beta, Serverless Components does not yet work with existing
serverless.ymlfiles. You will have to create a new
serverless.ymlfile. Additionally, Serverless Components are not yet integrated with the Serverless Framework Dashboard. We have some exciting announcements for this soon. Stay tuned.
I feel that the components implementation of APIs and Lambda functions are not quite as user-friendly as in the normal framework, but it sounds like an improvement for this is in the works, and will allow you to take advantage of the best of both worlds.
The other part of components I’m not so fond of is the management of state which is currently held in the native services themselves (rather than say, CloudFormation). I believe this is because you can spread components across cloud providers in a single template, however, I did find because of this the cleanup of servers wasn’t quite as expected; I had to remove the CloudFront distribution, certificate and DNS entries created by components manually even after initiating the
serverless remove command.
EDIT 7th August 2019: Austen Collins and Eslam A. Hefnawy got in touch to let me know that the CloudFront distribution and ACM certificate aren’t removed by design due to the amount of time it can take to clean up these resources.
It’s important to remember components is still in beta and looks to be a good start. I do feel there is some simple functionality lacking, like stages, and is better suited for smaller or more simple applications. Over time I believe this will improve and become more mature like Amplify.