The World of Cloud Functions
Liam Mackey
march 25th, 2019
Cloud functions are a great way to run small programmatic services in the cloud. They are easy to create and use, are very secure, and need little maintenance. They even scale on-demand in a way that is very difficult to achieve using regular servers.
Over the past few years, there has been a new player on the scene of cloud infrastructure. Cloud functions, such as Google Cloud Functions or Amazon’s Lambda functions, have popped up as a way to run applications in the cloud with no need to provision or monitor servers. Cloud functions are growing widely in popularity with providers, like GCP (Google Cloud Platform) and AWS (Amazon Web Services), expanding the capabilities of their cloud function offerings.
they’re cheap
I once built an application using Amazon Lambda functions and for the whole length of the campaign, we never paid more than two cents per three months for our use of the Lambda functions. On AWS, you can get up to 1,000,000 requests for free at the base memory level. Amazon’s affordable prices act as a low barrier to entry for those who want to experiment with cloud functions.
Recently, I used Google Cloud Functions to provide on-demand translations for all chat messages on a client’s platform. Despite giving the cloud functions the maximum 2GB of memory and a 200-second timeout, we still kept costs low, comparable to hosting the service on a private server. This was a smart infrastructure move, as the client was looking to clean up their GCP bill. Google’s pricing model is similar to Amazon’s in that they both keep costs low for cloud functions, in fact Google even allows for two million requests for free at the base memory level.
Using Google Cloud Functions:
they’re easy
Developing cloud functions is not too complex. Most cloud function providers allow you to develop locally and push your zip file to the cloud. Or you can edit the cloud function in the provider’s inline text editor directly in the cloud. In my experience, although the latter may sound easier, it’s usually better to develop locally because it allows you to write tests for your cloud function. Cloud providers offer tools like local emulators which when paired with testing libraries can help you make sure your function is working as expected when you deploy. Google’s Testing and CI/CD documentation was helpful to me when testing and deploying my first Google cloud function.
they have limits
Although cloud functions are useful there are drawbacks as well. In general, the file containing the cloud function code has to be less than 2MB in size, including external libraries. Run time can be an issue too. Most cloud providers do not allow functions to run for more than 300 seconds. Also, the costs for your cloud function are not merely driven by requests; memory usage and running time will affect the price you pay for your cloud application.
Continuous integration can be a crucial part of development with cloud functions. One of the ways to do this is to write procedures to deploy your code to the cloud provider. Most cloud function providers allow terminal tools like the AWS CLI or the gcloud CLI to zip up and deploy functions to the cloud quickly and securely.
Cloud providers like AWS and GCP allow for their cloud functions to be well integrated with their other services. This means that you can use your cloud functions for much more than simple API endpoints. For one project, I used Lambda functions in conjunction with many other AWS services ranging from S3 and DynamoDB to Elastic Transcoder and SES. I have also integrated Google Cloud Functions with services like Pub/Sub and Datastore. Cloud providers make it very easy for you to create complex architectures using cloud functions as communication providers for other services. This is a way that cloud functions work to their providers’ advantage as a way to make other less commonly used services more appealing and easier to work with.
they’re growing
As the popularity of cloud functions grow, more advancements are being made. For example, at the 2018 AWS re:Invent, Amazon announced that they will now support new runtimes for their cloud functions. And in December 2018 GitLab announced they will be launching their own serverless service for beta users. Cloud functions are growing in popularity, becoming more efficient, and easier to use.
Although cloud functions likely won’t replace servers any time in the near future, this doesn’t mean that you cannot integrate cloud functions into your site’s infrastructure. Cloud functions can be a great way to decouple complex services and isolate certain operations on your site which will make it easier to debug when things go wrong, as well as lower your cloud provider bill.
Cloud functions are becoming easier to use. With new runtimes being supported as well as new libraries that make it easier to use cloud functions as a way to integrate different cloud services, there has never been a better time to start experimenting with cloud functions than now.
An example of how to use AWS Lambda:
give it a shot
Cloud functions may not be the future of all development, but they are certainly a step in the direction towards cheap and simple cloud hosting. Since cloud functions are so cheap, I’d encourage anyone who is interested in the future of development to start playing around with cloud functions. Building skills for Amazon Alexa or Google Home is a great place to start. Or even writing a simple HTTP endpoint to perform simple operations and, if you’re inclined, hooking it up to a storage service to display a web page is a great way to learn as well. I hope that if you start playing around with cloud functions you’ll find them as wonderful, beautiful, and simple as I do. And even if you don’t, it’s always good to have another technology under your belt. Good luck and let me know what you create.
To help you dip your toe in this bold new world, you can find examples of how to build cloud functions on Google Cloud Platform and Amazon Web Services.
Tags: technology web-services aws gcp