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
-
OSJH and LPI Release 2024 Open Source Pros Job Survey Results
See what open source professionals look for in a new role.
-
Proton 9.0-1 Released to Improve Gaming with Steam
The latest release of Proton 9 adds several improvements and fixes an issue that has been problematic for Linux users.
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.