# 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](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) - [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html) - AWS-SDK-JS version [2.714.0](https://github.com/aws/aws-sdk-js/blob/master/CHANGELOG.md#27140) 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. ```shell aws configure ``` For configuration help, see https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html ### 1. Create an S3 bucket - Replace `` with your bucket name. - Replace `` with your region name (for ex. `us-west-2`). ```shell aws s3api create-bucket --bucket --region \ --create-bucket-configuration LocationConstraint= ``` ### 2. Create and upload dependencies to S3 bucket 1. [Install NodeJS](https://nodejs.org/). 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" ```shell aws s3 cp ./dependencies/nodejs.zip s3:/// ``` ### 3. Pack template with SAM ```shell sam package \ --template-file template.yaml \ --output-template-file packaged.yaml \ --s3-bucket ``` **DO NOT** run the output from above command. Instead, proceed to next step. ### 4. Deploy Cloudformation with SAM Replace `` with your stack name. ```shell sam deploy \ --template-file packaged.yaml \ --stack-name \ --capabilities CAPABILITY_IAM \ --parameter-overrides DependenciesBucket= ``` On completion, copy the value of `ApiURL`. Paste this value on line 8 of `/web-ui/src/config.js`: ```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: ```shell aws cloudformation describe-stacks \ --stack-name --query 'Stacks[].Outputs' ``` ### 5. Deploy UGC Web Demo Follow the steps in the [web-ui README](../web-ui) to get the UI running. --- ## Rest API Endpoints ### Sign Up Endpoint: `signUp`
Method: POST
Content Type: JSON
Payload: ```json { "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: `auth`
Method: POST
Content Type: JSON
Payload: ```json { "email": "My-Channel", "password": "My-Title" } ``` ### Get a User Endpoint: `user/username?access_token=`
Method: GET
Content Type: JSON
```json { "username": "username", "avatar": "avatar", "bgColor": "color", } ``` ### Update a User attribute Endpoint: `user/attr?access_token=`
Method: POST
Content Type: JSON
Payload: ```json { "Name": "picture", "Value": "My-New-Picture" } ``` ### Change Password Endpoint: `user/changePassword?access_token=`
Method: POST
Content Type: JSON
Payload: ```json { "oldPassword": "My-Old-Password", "newPassword": "My-New-Password" } ``` ### Delete a User Endpoint: `user/delete?access_token=`
Method: GET
Content Type: JSON
### Get IVS Stream Configuration Endpoint: `stream?access_token=`
Method: GET
Content Type: JSON
```json { "streamKey": "stream-key", "ingest": "ingest-server" } ``` ### List IVS Channels Endpoint: `channels`
Method: GET
Content Type: JSON
```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: `live-channels`
Method: GET
Content Type: JSON
```json [ { "username": "username", "avatar": "avatar", "bgColor": "color", "channelName": "channelName", "playbackUrl": "playbackUrl" }, ... ] ``` ### Get a Channel Endpoint: `channels/?id=` - Remember to `encodeURIComponent` channelArn
Method: GET
Content Type: JSON
### Reset Default Channel Stream Key Endpoint: `channels/default/streamKey/reset?access_token=`
Method: GET
Content Type: JSON
## Clean Up 1. Delete Cloudformation stack: ```shell aws cloudformation delete-stack --stack-name ``` 2. Remove files in S3 bucket ```shell aws s3 rm s3:// --recursive ``` 3. Delete S3 bucket ```shell aws s3api delete-bucket --bucket --region ```