My One Week’s Impression of Serverless, AWS Lambda, and AWS API Gateway (Aug 2016)
I went to an AWS Popup Loft event in SF about a week ago, learned about microservices, serverless architecture, AWS Lambda and API Gateway, and left super excited about this new way of deploying features and functionality.
The presentations Jim Tran gave can be found here and here.
What is Lambda?
Traditionally, you’ll deploy instances through EC2 and configure the OS, storage, and memory to your liking and then deploy your application on top of each instance.
If you’re ahead of the curve, you’ll have your application containerized and deploy it on a group of instances using ECS, Fleet, or Kubernetes. Instead of one application per instance, you’re now pooling resources together and letting a scheduler place where your application goes. This could mean multiple containers on a single host.
With Lambda, you’re not worrying about containers or fleets or which OS to run. You write code and let AWS Lambda manage the resources that allow your code to run. Sounds nice, right?
AWS calls Lambda an event-driven compute service. That means it runs arbitrary code without you managing servers and it runs only when it needs to run.
Lambda functions are stateless and trigger-based. They can be triggered through an API, AWS integrations, and third party triggers. I like to think of it as a pipe in a pipeline — input and output. It also doesn’t care what it previously processed.
Lambda right now only supports Node.js, Java, and Python but more languages are promised soon.
Why is Lambda so great?
A few reasons why Lambda seems promising:
- Less operational worries. Outsourcing management of a fleet of servers with Docker and containers saves time and brain power.
- Potentially lower cost. You’re charged by allocated memory and execution of your code. I’ve heard that the break-even point is 40% utilization. If your ECS fleet is <40% utilized, Lambda is cheaper iirc. (This will likely change too)
- Hands-off scalability. Lambda will provision more functions as needed to handle increased traffic. Partnered with a managed data store like DynamoDB (just make sure you have alerts on your provisioned throughput), and you’re good to go.
Hands-on Experience with Lambda, API Gateway, and the Serverless Framework
Jim walked through a microservice demo of deploying endpoints managed by API Gateway which triggers Lambda functions that query a table in DynamoDB. It was a great demo which I wish was recorded. I won’t guide you through it but this tutorial does the same CRUD actions.
I wanted to give these services a try but the GUI interface wouldn’t cut it for me. If you want to deploy at a production level, you can’t copy and paste code into their GUI and generate aliases as your versioning. It’s just wrong.
Jim recommended checking out the Serverless Framework at the end of his talk so I thought I’d try it out.
Their tutorial is very straight forward and after trying the AWS Tutorial, I recommend giving Serverless a try.
You write your endpoint handlers in Javascript and define your event handlers in a `serverless.yml` file. The `serverless.env.yml` file allows you to define stages such as development, staging, and production. Also, the command line tool makes deployment as easy as `sls deploy`. Pretty neat tool. Feels like a higher-level Terraform.
It was fun and great to not worry about the underlying infrastructure needed to bring my API proxy experiment to life but I did run into some limitations.
Limitations and Future of Serverless Framework
A big limitation as of 1.0.0.beta.2 was that there was no support for a local development environment. This made the testing iterations of my functions 20–30 seconds very painful. (Especially since I was new with Node)
The probably with having a local development environment with Lambda and API Gateway is that Lambda and API Gateway is a black box to the consumer. The only contract they provide us is the ability to run the code and not specifying how the containers work or even if they use containers. How do we mimic a development environment to a black box?
With many assumptions.
I think the Serverless Framework will develop a local development environment that works well enough to mimic the environment AWS gives us but we’ll need to test thoroughly on the development and staging environment hosted on AWS.
Serverless has a lot of traction going forward and the team behind it is very open and receptive to help. Check out their help-wanted-easy label for issues you can easily dive into!
Wrapping up
Overall, I’m very excited about Lambda and API Gateway. There are still unanswered questions about development and workflows before I can consider it easily consumed in Production but there are many dedicated people inside and outside who want Serverless architecture become mainstream and are working hard to make it so.
Resources
- Introduction to Microservices by Jim Tran, Principal Solutions Architect, AWS
- Getting Started with AWS Lambda and the Serverless Cloud by Jim Tran, Principal Solutions Architect, AWS
- Tutorial: Using AWS Lambda with Amazon API Gateway (On-Demand Over HTTPS)
- Serverless Framework
- Interview with Mike Roberts on Serverless Architecture
- Great, long, article on Serverless Architecture also by Mike Roberts