How to Create a podcast downloader using serverless technology

It’s been a long time since we have seen an increase in the number of serverless technologies on the internet, developers and system architects are occupying AWS Lambda and other stateless functions which don’t need procuring a server whenever you are trying something new. Apart from the old school container technology, developers are now preferring IBM OpenWhisk.

Basically, if you need more control on your server then probably one will pick a Virtual Machine instance, but in case if you don’t want to mess with OS caching, monitoring and scaling the resources then IBM OpenWhisk is the perfect choice for you.

In this article, we are going to demonstrate How to Create a podcast downloader using serverless technology. We will use IBM OpenWhisk for creating a podcast, and we will set up the flask application to send requests and then download the content from the OpenStack Swift object storage.

How does this thing work?

Basically, it works with Python +  MySQL, A python app is set locally and for storing the database MySQL is used. A virtual environment in a Zip file is uploaded on the IBM cloud functions which contains Python actions. Now the user interacts with the Local app and it will provide the required action. Moreover, object storage OpenStack Swift will be used for storing the data.

Components required

  1. IBM cloud object storage:  It is a cost-effective high availability data storage service which provides faster and structured cloud data storage option to the market.
  2. OpenWhisk: It is a highly scalable serverless environment where you can execute your code easily.

Prerequisite

You’ll need a Bluemix account, also you’ll need to be familiar with OpenWhisk commands and make sure you install Bluemix CLI and the Cloud functions Plugin.

Requirements

Python 2.7

Packages from requirements.txt

Curl or Similar tool.

MySQL DB server.

Steps for Installation

First of all, make sure you have all the packages, MySQL and Python 2.7 installed locally. Once you have finished this, you can move further.

1. Clone Repo from Github and go to the directory.

Make sure you have git package installed on your server, or just type apt install git to install git package on Ubuntu.

git clone https://github.com/IBM/PodcastDownloader && cd PodcastDownloader

2. Create a MySQL database for Podcast Downloader.

Considering that you already have MySQL working properly on your server, we will create podcast_dowonloader.sql.

 

mysql -u user -p < podcasts_downloader.sql

3. Enable Podcasts manager.

Now we have to enable the podcast manager API server. We will use flask here and we will enable debugging too!

export FLASK_APP=podcasts_manager.py

export FLASK_DEBUG=1

elask run

4. Make podcast, user, and subscription on the server.

Now we will use curl to create users and their subscriptions. Consider that your API server is working locally and you’ll use port 5000.

 

Create new user.

curl -X POST “http://localhost:5000/customer?name=liu”

 

Create Podcast.

curl -X POST “http://localhost:5000/podcast?podname=google&url=https://www.ted.com/talks/rss”

 

Create Subscription.

curl -X POST “http://localhost:5000/sub?customerid=1&podid=1”

5. Make python Zip Action.

Before doing this step make sure python2action docker image is already built, and the docker is installed locally.

cp DownloaderAction.py  __main__.py

 

Now we need to integrate the downloader action in OpenStack swift client. So, basically we need to replicate VCAP_SERVICES.json with the storage service access and authentication details, so the downloader will read VCAP_SERVICES and you’ll be able to authenticate and provide the download easily.

Make zip action.

 

docker run –rm -v “$PWD:/tmp” openwhisk/python2action sh -c “cd tmp; virtualenv virtualenv; source virtualenv/bin/activate; pip install -r requirements.txt;”

 

zip -r wgetPython.zip virtualenv __main__.py VCAP_SERVICES.json

 

6. Deploy to OpenWhisk.

Now we need to push and deploy the downloader action which we already have to the OpenWhisk platform.

 

bx wsk action create wget Python –kind python:2 wgetPython.zip

7. Invoke the action from the podcast manager to download.

 

curl -X POST  -m 50 “http://localhost:5000/download?customername=liu&downloader_url=https://openwhisk.ng.bluemix.net/api/v1/namespaces/<cf_org>_<cf_space>/actions/wgetPython”

 

Now you’ll be able to run the podcast manager easily! So, this was all about how to create a podcast downloader with OpenWhisk serverless technology! Hit us in the comment section below if you have any doubts.

 


Feel Free to share your thoughts in the comment section below.
Don't forget to follow us on Twitter, like our Facebook Fan Page and Add us to your circles on Google+ to keep you updated with the latest technology news, gadget reviews, launches around the world and much more
About Pulkit Juneja
Pulkit Juneja, is the founder of Versed Tech. A born tech savvy guy who loves to write content on latest technology news, Gadget reviews, android app reviews, SEO and Much More. Connect with us at pulkit@versedtech.org