Linux Format

Serverless framework..........

Deploy cloud-scale applicatio­ns in a few lines of code with absolutely no need for any servers with the help of Dan Frost.

-

Dan Frost hates servers, so he deploys cloudscale applicatio­ns with just a few lines of code from his golden chariot in the sky that’s running on Amazon Lambda.

Serverless computing offers the ability to build scalable, production-ready code without the need to deploy or manage servers at all. For many of us, this is what cloud computing was always meant to be: no longer thinking about servers, paying infrastruc­ture and managing complex scaling rules.

You can use Serverless programmin­g to build backends for apps, websites, virtual reality, data pipelines and more. In fact, pretty much anything you can build on a server you can also build Serverless.

In this tutorial, we’ll see how to use Serverless programmin­g to build a basic data pipeline that checks for interestin­g or suspicious lines in logs and pushes the results to a NoSQL database – DynamoDB. The pipeline – where you build a series of functions that are tied together by events – is fundamenta­l to Serverless programmin­g. You can use this pattern to transform images, generate video, data mine and more or less anything else.

In our example, we’ll provide an API for people to push files and a second function that scans them for keywords. This can be used for analysing log files, finding tweets mentioning specific words or finding companies mentioned in the news. The code to spot the words is very simple but it lets us focus on the Serverless architectu­re.

I’ll cover everything you need to install, but you can dig into more of the framework at https://serverless.com/ framework/docs/. All the code is available at https:// github.com/danfrost/serverless-programmin­g-tutorial.

The serverless framework

The line of progress in computing history goes from large to small; from huge computers to tiny smartphone­s. And in programmin­g, it descends from monolythic servers running huge programs to tiny, very specific microservi­ces doing just a few things really well.

But when you build a microservi­ce – say, something that resizes images and puts your logo on it to be shared on social media, or something that sniffs packages for suspicious data – that service still has to run somewhere. Typically, you run a server, install software on it, manage its backups and monitor its uptime to make sure it’s available all the time.

Some systems feel like they need servers – Wordpress or e-commerce sites are built on software that assumes that there will be a server there. But some code doesn’t need a whole server. I’ve deployed dozens of scripts that run once a day to glue a few systems together, or monitor traffic, or record stats. These don’t need a server and often end up being deployed to random servers, but it doesn’t feel like the right place.

This is where Serverless computing comes in. Instead of deploying a server, you create and deploy ‘functions’ that are very specific in their scope. Like Unix commands, they do one thing and they do it very well. These

functions can be as simple as a few lines of python or they can require binaries for analysing images. It’s up to you. But the best practice, and the trend in Serverless computing, is to write each function for a very specific, very targeted use case.

The functions are triggered by ‘events’, which can come from a number of places. If you’re thinking of writing an API for your app, as we’re going to do in this example, you can hook up the functions to API EndPoints. Or if you want to process a file, you can have Amazon’s file store, S3, trigger the events. You can even trigger events from Facebook messenger, which allows you to build chat apps with very minimal effort. what’s created: $ npm install -g serverless $ serverless create --template aws-python --path My Server less Project $cd My Server less Project && ls handler.py serverless.yml

The Serverless project directory is fairly lean with only two files created: and serverless.yml. Serverless.yml is where the project is configured, and handler.py contains the functions that will be triggered. Create an IAM profile for yourself and set up your credential­s: serverless config credential­s -p aws -k XXX -s XXXXX --profile tutorial-profile

 ??  ??
 ??  ?? AWS can be fiddly to wire together but serverless lets you cheat. Here, it has configured an API gateway thanks to just a few lines of config.
AWS can be fiddly to wire together but serverless lets you cheat. Here, it has configured an API gateway thanks to just a few lines of config.

Newspapers in English

Newspapers from Australia