Deploying a Serverless Youtube-To-Gif Telegram bot with OpenFaaS

Eric Stoekl
Sep 26, 2017 · 6 min read
Because it’s running OpenFaaS, you can replace the EC2 instance with any other kind of server imaginable. Raspberry Pi, bare-metal, etc.
Create a GIF from any YouTube video

1. Create the Telegram Bot

2. Deploy OpenFaaS on EC2

Select the ‘Ubuntu Server 16.04’ AMI
repo_update: true
repo_upgrade: all

- curl -sSL | sudo sh
- sudo usermod -a -G docker ubuntu
- docker swarm init
- cd /tmp
- git clone -b higherTimeout
- cd ./faas
- ./
- cd /tmp
- curl -sSL | sudo sh
OpenFaaS listens on port 8080, so keeping this port open is essential.
$ ssh -i <your-key-pair.pem> ubuntu@<your-ec2-public-dns>
Pass some markdown to the ‘func_markdown’ function and hit ‘Invoke’ to test that your OpenFaaS deployment is up and running

3. Deploy the core functions of the Youtube-To-Gif Telegram bot on OpenFaaS

~ $ git clone
~ $ cd tg-youtubegif
lang: node
handler: ./telegram-gif-bot
image: ems5311/telegram-gif-bot:0.2
write_timeout: 65
read_timeout: 65
write_debug: true
~/tg-youtubegif $ faas-cli build -f tg-youtubegif.yml
~/tg-youtubegif $ faas-cli deploy -f tg-youtubegif.yml
curl <your-AWS-public-DNS>:8080/function/youtube-dl -d "" | curl -X POST <your-AWS-public-DNS>:8080/function/gif-maker --data-binary @- > yt.gif
If you get a file containing this, congrats, your OpenFaaS deployment works!

4. Create the API Gateway

The Telegram bot will send messages to this gateway through HTTP POST requests
{"ok":true,"result":true,"description":"Webhook was set"}
If you see this result when you paste a YouTube video to your Telegram bot, congratulations!


 by the author.

Eric Stoekl

Written by

Fan of Open Source and DevOps. OpenFaaS contributor.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade