# Deployment instructions for the demo backend and Amazon IVS channel Deploy the simple chat backend, create a new Amazon IVS channel using AWS CloudFormation, and retrieve everything you need to configure the demo. ## Prerequisites * Access to AWS Account with permission to create IAM role, and Lambda. * [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) ## Deploy from your local machine Before you start, run the following command to make sure you're in the correct AWS account (or configure as needed): ``` aws configure ``` For additional help on configuring, please 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. ``` aws s3api create-bucket --bucket --region \ --create-bucket-configuration LocationConstraint= ``` ### 2. Pack template with SAM ``` sam package \ --template-file template.yaml \ --output-template-file packaged.yaml \ --s3-bucket ``` DO NOT run the output from above command, proceed to next step. ### 3. Deploy Cloudformation with SAM Replace `` with your stack name. ``` sam deploy \ --template-file packaged.yaml \ --stack-name \ --capabilities CAPABILITY_IAM ``` On completion, save the following values: 1. `WebSocketURI`, used in the demo configuration file (`config.js`), to send/receive chat messages 2. `ChannelIngestEndpoint`, to be used in your broadcasting software (ex. OBS) 3. `StreamKey`, to be used in your broadcasting software (ex. OBS) 4. `ChannelPlaybackUrl`, used in the demo configuration file (`config.js`), to load your Amazon IVS stream in the video player If needed, to retrieve Cloudformation stack outputs again, run below command: ``` aws cloudformation describe-stacks --stack-name aws cloudformation describe-stacks \ --stack-name --query 'Stacks[].Outputs' ``` ### 4. (optional) Testing the chat API To test the WebSocket API, you can use [wscat](https://github.com/websockets/wscat), an open-source command line tool. 1. [Install NPM](https://www.npmjs.com/get-npm). 2. Install wscat: ``` bash $ npm install -g wscat ``` 3. On the console, connect to your published API endpoint by executing the following command: Replace `` with your WebSocketServer URL created when deploying with cloudformation. ``` bash $ wscat -c ``` 4. To test the sendMessage function, send a JSON message like the following example. The Lambda function sends it back using the callback URL: Replace `` with your WebSocketServer URL created when deploying with cloudformation. ``` bash $ wscat -c connected (press CTRL+C to quit) > {"action":"sendmessage", "data":"hello world"} < hello world ``` ### 5. Configure the Simple Chat demo frontend Follow the [detailed instructions](../web-ui) on how to get the frontend up and running. ### 6. (optional) Clean Up 1. Delete Cloudformation stack: ``` aws cloudformation delete-stack --stack-name ``` 2. Remove files in S3 bucket ``` aws s3 rm s3:// --recursive ``` 3. Delete S3 bucket ``` aws s3api delete-bucket --bucket --region ```