Set up Amazon Web Services
Hidden Lambda
If you want to run programs on Amazon's back-end servers instead of just serving static web pages, you can opt for the Lambda offering. It runs JavaScript, Python, and Java functions in isolated containers, triggered either via a web API or associated with events from other services.
For example, Amazon's dynamic database Dynamo can generate an event if a new data record arrives; this in turn triggers a Lambda function that performs further steps in the workflow. A cloud application defined this way thus does not consist of a flow that is orchestrated by the program logic but is formed by linking individual components and their events to create an overall architecture.
In the world of Lambda, the Python script in Listing 1 [5] provides a test function. On the web console, you need to press the Lambda option in the Computing section to do this. After showing an overview, the service prompts you to Select blueprint for the test function. For your tests, select the Blank function and skip the next page, Configure triggers; then, enter a name for the Lambda function on the following page (as shown in Figure 7; wellHelloThere in this case) and copy the code from Listing 1 to the text box shown below the Edit code inline drop-down.
Listing 1
greet.py
On the following page (Figure 8), the console has already entered the name of the handler function. Because a run-time environment might include multiple files with many functions, you need to specify both the filename and the function it contains here.
Leave the default Role for execution rights – that is, Create new role from template(s) – and specify a suitable name later (myBasicExecutionRole in this case). After confirming, Amazon installs the Lambda function in the cloud and lets the user test it (Figure 9). You can add some parameters in JSON format, which the script dynamically evaluates later.
The aws
command-line client also has access to the Lambda script. As the call in Figure 10 shows, the tool takes the name of the function previously defined in the Web UI (wellHelloThere
; i.e., not the name of the Python function) and a JSON hash with input parameters as --payload
; this remains empty in the test case. Later, any parameters provided by the web server end up in the event
parameter of the Python function that then interprets them dynamically.
Now you need to teach the Lambda script to accept the URL with a video as input, fetch it off the web, and run the motion analysis program [2] on it. This requires more than a simple Python script without dependencies; in fact, you need a run-time environment with the OpenCV library and a precompiled static binary installed. To discover how this works and how to package the results, feed them to the cloud, and define a web service that both triggers the procedure and returns the results as an image file, tune in to next month's column.
Mike Schilli
Mike Schilli works as a software engineer in the San Francisco Bay Area. He can be contacted at mailto:mschilli@perlmeister.com. Mike's homepage can be found at http://perlmeister.com.
Infos
- AWS usage rates for free operation: https://aws.amazon.com/free
- "Video Preview" by Mike Schilli, Linux Pro Magazine, issue 195, February 2017, p. 52, http://www.linuxpromagazine.com/Issues/2017/195/Perl-Video-Preview
- Poccia, Danilo. AWS Lambda in Action, Manning, 2017
- Rady, Ben. Serverless Single Page Apps: Fast, Scalable and Available, The Pragmatic Bookshelf, 2016
- Listings: ftp://ftp.linux-magazine.com/pub/listings/magazine/195
« Previous 1 2
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.
-
DebConf24 to be Held in South Korea
Busan will be the location of the latest DebConf running July 28 through August 4