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.
The source code for this guide can be found at:
https://github.com/techreturners/zoom-api-service
An artistic depiction of what our (soon to be your!) code is doing!
First of all you need to:
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):
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
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
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...
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:
Fun Fact: YAML stands for 'Yet another markup language'.
Make sure:
Now for the handler.js file...
In your handler.js file require or import your packages:
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!)
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:
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.
⛅️💜🙌