Lambda@Edge function for authorizing access to private room resources in educandu
npm install @educandu/rooms-auth-lambda
Lambda@Edge function for authorizing access to private room resources in educandu.
* node.js ^18.0.0
* optional: globally installed gulp: npm i -g gulp-cli
The output of this repository is an npm package (@educandu/rooms-auth-lambda) as well as a zip file containing the Lambda@Edge function.
The handler in this package is supposed to run as a Lambda@Edge function in AWS.
~~~sh
export SESSION_COOKIE_NAME="SESSION_ID" # mandatory
export WEBSITE_BASE_URL="https://consuming-website.com" # mandatory
export X_ROOMS_AUTH_SECRET="
export DISABLE_LOGGING="true" # optional, defaults to logging being enabled
~~~
As AWS Lambda@Edge function do not support environment variables, any values have to be injected into the code itself after deployment, for example at the top of the bundle file:
~~~js
process.env.SESSION_COOKIE_NAME = 'SESSION_ID';
process.env.WEBSITE_BASE_URL = 'https://consuming-website.com';
process.env.X_ROOMS_AUTH_SECRET = "
~~~
Run gulp build and you will find a single script file index.js in the dist folder which contains a bundle of all code needed to run on AWS. You will also find a file lambda.zip in the pack folder containing the bundle. This can be used for automated deployments on AWS (The Github action publish creates a release on Github and uploads this zip file).
~~~sh
yarn add @educandu/rooms-auth-lambda --dev
~~~
~~~js
import { handler } from '@educandu/rooms-auth-lambda';
handler(event, context, (error, result) => {
// Do something
});
~~~
This package comes with a development server that can be used for testing the lambda locally. The server object returned by the call is the object you would get when starting an express server.
~~~sh
yarn add @educandu/rooms-auth-lambda --dev
export SESSION_COOKIE_NAME="SESSION_ID"
export WEBSITE_BASE_URL="http://localhost:3000"
export X_ROOMS_AUTH_SECRET="
~~~
~~~js
import { startDevServer } from '@educandu/rooms-auth-lambda';
const port = 10000;
const cdnBaseUrl = 'http://localhost:9000/my-bucket';
const server = startDevServer(cdnBaseUrl, port, err => {
// Do something with err
});
// Then, in the end, close the server:
server.close(err => {
// Do something with err
});
~~~
~~~sh
yarn add @educandu/rooms-auth-lambda --dev
export PORT=10000
export CDN_BASE_URL="http://localhost:9000/my-bucket"
export SESSION_COOKIE_NAME="SESSION_ID"
export WEBSITE_BASE_URL="http://localhost:3000"
export X_ROOMS_AUTH_SECRET="
node ./node_modules/@educandu/rooms-auth-lambda/src/dev-server/run.js
~~~
---
Funded by 'Stiftung Innovation in der Hochschullehre'
)
A Project of the 'Hochschule für Musik und Theater München' (University for Music and Performing Arts)

Project owner: Hochschule für Musik und Theater München\
Project management: Ulrich Kaiser