Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Latest commit

 

History

History

serverless

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Serverless App Setup

Prerequisites

  • Access to an AWS Account with permissions to create: IAM role, DynamoDB, Cognito, Lambda, API Gateway, S3, and Cloudformation.
  • AWS CLI Version 2
  • AWS SAM CLI
  • AWS-SDK-JS version 2.714.0 or greater for IVS support

Deploy from your local machine

Before you start, run the following command to make sure the AWS CLI tool is configured correctly.

aws configure

For configuration help, see https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html

1. Create an S3 bucket

  • Replace <my-bucket-name> with your bucket name.
  • Replace <my-region> with your region name (for ex. us-west-2).
aws s3api create-bucket --bucket <my-bucket-name> --region <my-region> \
--create-bucket-configuration LocationConstraint=<my-region>

2. Create and upload dependencies to S3 bucket

  1. Install NodeJS. Download latest LTS version ("Recommended for Most Users")
  2. Navigate to the serverless dependencies directory serverless/dependencies/nodejs on your local computer. Example: ~/Developer/amazon-vs-ugc-web-demo/serverless/dependencies/nodejs
  3. Run: npm install
  4. Compress the serverless dependencies directory serverless/dependencies/nodejs into a .zip file named nodejs.zip.
  5. Upload the zipped dependencies to the previously created S3 bucket"
aws s3 cp ./dependencies/nodejs.zip s3://<my-bucket-name>/

3. Pack template with SAM

sam package \
--template-file template.yaml \
--output-template-file packaged.yaml \
--s3-bucket <my-bucket-name>

DO NOT run the output from above command. Instead, proceed to next step.

4. Deploy Cloudformation with SAM

Replace <my-stack-name> with your stack name.

sam deploy \
--template-file packaged.yaml \
--stack-name <my-stack-name> \
--capabilities CAPABILITY_IAM \
--parameter-overrides DependenciesBucket=<my-bucket-name>

On completion, copy the value of ApiURL. Paste this value on line 8 of /web-ui/src/config.js:

// config.js
...
export const UGC_API = ""; // paste the ApiURL value here
...

Example of ApiURL: https://xxxxxxxxxx.execute-api.{my-region}.amazonaws.com/Prod/

To retrieve Cloudformation stack outputs again, run the following command:

aws cloudformation describe-stacks \
--stack-name <my-stack-name> --query 'Stacks[].Outputs'

5. Deploy UGC Web Demo

Follow the steps in the web-ui README to get the UI running.


Rest API Endpoints

Sign Up

Endpoint: <ApiURL>signUp
Method: POST
Content Type: JSON
Payload:

{
  "email": "My-Channel",
  "password": "My-Title",
  "avatar": "My-Avatar",
  "bgColor": "My-Background-Color",
  "channelLatencyMode": "My-Channel-Latency-Mode", // Optional - default to NORMAL
  "channelType": "My-Channel-Type, // Optional - default to BASIC
}

Auth

Endpoint: <ApiURL>auth
Method: POST
Content Type: JSON
Payload:

{
  "email": "My-Channel",
  "password": "My-Title"
}

Get a User

Endpoint: <ApiURL>user/username?access_token=<my_access_token>
Method: GET
Content Type: JSON

{
  "username": "username",
  "avatar": "avatar",
  "bgColor": "color",
}

Update a User attribute

Endpoint: <ApiURL>user/attr?access_token=<my_access_token>
Method: POST
Content Type: JSON
Payload:

{
  "Name": "picture",
  "Value": "My-New-Picture"
}

Change Password

Endpoint: <ApiURL>user/changePassword?access_token=<my_access_token>
Method: POST
Content Type: JSON
Payload:

{
  "oldPassword": "My-Old-Password",
  "newPassword": "My-New-Password"
}

Delete a User

Endpoint: <ApiURL>user/delete?access_token=<my_access_token>
Method: GET
Content Type: JSON

Get IVS Stream Configuration

Endpoint: <ApiURL>stream?access_token=<my_access_token>
Method: GET
Content Type: JSON

{
  "streamKey": "stream-key",
  "ingest": "ingest-server"
}

List IVS Channels

Endpoint: <ApiURL>channels
Method: GET
Content Type: JSON

[
  {
    "username": "username",
    "avatar": "avatar",
    "bgColor": "color",
    "channelName": "channelName",
    "playbackUrl": "playbackUrl",
    "isLive": "yes/no",
    "startTime": "2022-02-17T22:55:30.000Z" // "0" if offline
  },
  ...
]

List Live Channels

Endpoint: <ApiURL>live-channels
Method: GET
Content Type: JSON

[
  {
    "username": "username",
    "avatar": "avatar",
    "bgColor": "color",
    "channelName": "channelName",
    "playbackUrl": "playbackUrl"
  },
  ...
]

Get a Channel

Endpoint: <ApiURL>channels/?id=<username> - Remember to encodeURIComponent channelArn
Method: GET
Content Type: JSON

Reset Default Channel Stream Key

Endpoint: <ApiURL>channels/default/streamKey/reset?access_token=<my_access_token>
Method: GET
Content Type: JSON

Clean Up

  1. Delete Cloudformation stack:
aws cloudformation delete-stack --stack-name <my-stack-name>
  1. Remove files in S3 bucket
aws s3 rm s3://<my-bucket-name> --recursive
  1. Delete S3 bucket
aws s3api delete-bucket --bucket <my-bucket-name> --region <my-region>