Writing a lambda API that integrates with Zoom
In this tutorial we will show you how to write a lambda API that integrates with Zoom!

Posted on May 12th, 2020 by Ellie

The world is experiencing an increased adoption of remote working and one of the most popular tools for the conference call/webinar option is Zoom.

Over the course of this blog we're going show how you can write an AWS Lambda function to register someone for one of your Zoom webinars.

TL;DR

The source code for this guide can be found at:

https://github.com/techreturners/zoom-api-service

Artistic depiction of what our code is doing curtesy of James Heggs aka whiteboard master

An artistic depiction of what our (soon to be your!) code is doing!

Pre-requisites

First of all you need to:

  1. Set up an aws account (if you haven't got one already): https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/
  2. Create a serverless IAM (acronym for Identity and Access Management) user. It is this "user" (account) that we are going to connect to through serverless, so for clarity's sake call yours “serverless”: https://www.youtube.com/watch?v=KngM5bfpttA
  3. This serverless IAM account will generate you a secret access key and password. Download these, we'll need them later!

Serverless Setup

Now we need to install serverless to our computer:

Hint: Serverless computing basically means you don’t have to worry about servers - yay! You write code (as "infrastructure") and when the code is run/deployed the programme sets up all of your servers in the "cloud" for you. Serverless is just the name of one of these "Infrastructure as Code" technologies. You could use Terraform or Puppet to do something similar.⛅️

To install serverless, go to your terminal and run:

npm install -g serverless

You should get a little success message like this (please ignore the crazy colour of my terminal, it picks colours at random):

Serverless succressfully installed

Let's get your AWS access key and Secret access key printed to screen as we'll need those values shortly. Tthey are probably in your downloads folder):

cat ~/Downloads/accessKeys.csv 

Access key ID,Secret access key
AKIASOMEKEY,m6TFsSOMESECRETACCESSKEY

The Serverless Framework needs access to your cloud provider account so that it can create and manage resources on your behalf. This is done by providing your AWS credentials in the config/set up and tells AWS which IAM account you’d like to connect to, like this:

serverless config credentials --provider aws --key YOUR_ACCESS_KEY_ID --secret YOUR_SECRET_ACCESS_KEY --profile serverless

And you should see something like this...

Serverless: Setting up AWS...

To check your AWS credentials/secret access keys have been saved you can print them to your terminal screen like so:

tech-returners cat ~/.aws/credentials 

[serverless]
aws_access_key_id=AKIASVF54FGKBC2cfghjkCFiuygfghBRGRJHFY7GS
aws_secret_access_key=m6TFsAu+G0HU50iKTxBPDFGHQhWNQQqA57xsOJJU1xAdbs

Solution code

Create your serverless project with node.js by downloading a template file structure (infrastructure as code! 💪) offered by serverless. You can call your project whatever you’d like, we have called ours zoom-api-service. This command downloads your serverless code template:

serverless create --template aws-nodejs --path zoom-api-service

Serverless boilerplate

Now CD into your new serverless “zoom-api-service” directory and make a package.json file (as serverless doesn’t create one for you):

cd zoom-api-service
npm init

Download and install the packages you will need to create...

  • your json webtoken (which you will use to authenticate who you are to zoom),
  • express because we will be serving back the data we receive from zoom,
  • axios for making your http requests and serverless-http (to “wrap” your api for serverless use/is a handy piece of middleware that handles the interface between your Node.js application and the specifics of API gateway).

In your terminal project directory run the command:

npm install jsonwebtoken express axios serverless-http

In your serverless.yml file you will want to trim all the fluff you don't need and add bits that you do need, until you have something that looks like this:

Serverless.yml code

Fun Fact: YAML stands for 'Yet another markup language'.

Make sure:

  • Your syntax and spacing is super accurate as .yaml file is verryyyy picky about this
  • Your service is the name you’ve given your project (zoom-api-service)
  • You have chosen the region you would like your Lambda function and server to run in
  • You have specified the name of your function (we called ours zoom)
  • When you deploy with serverless deploy you'll need to specify your ZOOMAPIKEY and your ZOOMAPISECRET. Saving environment variables this way also means your code is safe to push to version control/github. 🙌
  • You can get your Zoom API key and secret by creating an app and registering it with their SDK.
  • You are making a post request (as we will be sending user information and our json webtoken to zoom)
  • Make sure you have enabled cors!

Now for the handler.js file...

In your handler.js file require or import your packages:

Handler.js import

Using express we are going to handle a post request to our AWS Lambda API. We are using express here because we will want to send/”serve” data back to our frontend. The function you write now will be your Lambda function in the clouds⛅️😍 and is what your front end API request could trigger and that request is subsequently sent on to the Zoom API.

I have written some comments explaining what each bit of this code is doing (feel free to modify it and make it your own!)

Handler.js post request code

After writing your functions (check for any formatting or spelling errors) we want to deploy our code (send it up to the servers in the sky). In your terminal run:

serverless deploy --ZOOM_API_KEY "YOUR_ZOOM_API_KEY" --ZOOM_API_SECRET "YOUR_ZOOM_SECRET"

Print your shiny new API endpoint to the terminal:

serverless info

To test if your API is working you can use Postman (download here: https://www.postman.com/) to make a POST request and send in the required details for your webinar as the POST body like so:

Postman example

Your response should include the name of your webinar and signup URL's.

NOTE: Zoom will automatically send the signup email to your registrant for you.

How you use your endpoint is up to you! We used a paypal button which once the users payment was successful sent their details off to our API, and then onto Zoom so they could be registered for our webinar.

⛅️💜🙌