Serverless on AWS: Let’s Get Started!
If you’ve been to any cloud conference, browsed around ‘cloud twitter’ a bit or are in the process of starting your cloud journey, it’s a sure guarantee you’ve heard about serverless by now. Is it just a buzzword, or is serverless something you can really start to get your hands dirty with and benefit from?
Accessing compute power became much easier when “the cloud” entered the market. Now, rather than waiting for bare metal servers to arrive, installing them into racks, and cabling during installation, you can set up your servers with only a few clicks on the web console. Yet although provisioning today’s servers takes only minutes, you still need to prepare and maintain them by patching, installing necessary packages, and setting up environment variables. This takes time. So how do you remove this overhead? You go serverless!
In the first article of this three-part series, we discuss the serverless basics: what it is, where it came from, why you would want to use it and how to optimize your serverless experience.
What do you mean Serverless? Are there really no servers?
Everyone’s first question is… how can there be no servers? Despite what the name suggests, servers don’t just disappear into thin air. There are still servers there, but you aren’t managing them and you aren’t worrying about taking care of expenses. That’s where the cloud comes in and makes our lives much more efficient. AWS has taken away the busy work so we only pay for computing power and necessary memory.
The core idea of serverless is to allow you to deploy your application with just a few clicks by simply choosing the desired programming language and its version, along with the necessary dependencies. Serverless removes infrastructure and operating system complexities while retaining benefits like scalability, high availability, and fault tolerance. At the same time, it allows you to pay only for what you use, making it an invaluable concept for many today.
So how did this whole Serverless thing start?
As technology progressed back in the bare metal days, we saw significant innovation. In the early 2000s, interesting concepts like virtualization and software as a service (SaaS) were introduced, followed by containerization and platform as a service (PaaS) years later. But everything changed in 2006 when Amazon—already well-known—ushered us into the “cloud” era with its infrastructure as a service (IaaS) offering, Amazon Web Services (AWS). Amazon also introduced the concept of “serverless,” when in 2014, it released AWS Lambda, its function as a service (FaaS) product.
Introducing… AWS Lambda!
AWS Lambda essentially functions as a service, allowing you to execute a piece of code on managed servers with no provisioning or administration (although you don’t have OS access). It will run your code when required, but will also scale automatically, allowing thousands of requests per second. To do this, simply pass your code in one of the supported languages (Node.js, Java, C#, Go, or Python) and set the desired triggers that will start the execution.
AWS Lambda can be run when an event like uploading to S3 or receiving an SNS message occurs. It can also be used as a scheduled cron job or even manually according to need, making it suitable for data processing, automating infrastructure pipelines, and more. AWS Lambda can also be used to create applications—from serverless websites to the Internet of Things to mobile backends.
When Amazon introduced the concept of “serverless” in 2014, deploying applications became much easier and more efficient. AWS Lambda is a fairly simple tool, yet its ability to save time, money and other resources is significant. By following the tips outlined in this article, you can integrate AWS Lambda with other AWS services, further streamlining your experience.
AWS Lambda Tips and Tricks
Because AWS Lambda is an AWS product, it integrates easily with other AWS services. You can use this to your advantage by following the tips and tricks below.
1. Working around Limits
One way to work around AWS Lambda limits is to create multiple functions and combine them utilizing other services like AWS Step Functions. AWS Step Functions can link Lambda functions together, introduce a delay before triggering (which many think should have been an out-of-the-box option), and react differently to specific errors caught during the execution of the function.
2. Understand Retries and Dead Letter Queues
You can invoke a Lambda function synchronously (waiting for the function to finish before moving on) or asynchronously (moving on immediately after invoking the function). When AWS Lambda is invoked asynchronously, it is retried twice on failure with delays in between. It is important to understand this retry behaviour so you can choose the appropriate triggers for your function. Also, consider using Dead Letter Queues to direct unprocessed events for further analysis.
3. Errors and Metrics
To monitor your Lambda functions, use existing AWS Lambda metrics and Amazon CloudWatch alerts, which allow you to create various alarms. For example, you can create an alarm based on the expected duration of your functions’ execution times, helping you address bottleneck issues