项目作者: ahmetatalay

项目描述 :
AWS Serverless Live Streaming project which created by mainly AWS Amplify, AWS Appsync, AWS Elemental MediaLive, AWS Elemental MediaPackage.
高级语言: JavaScript
项目地址: git://github.com/ahmetatalay/aws-serverless-live-streaming.git
创建时间: 2020-06-03T20:27:16Z
项目社区:https://github.com/ahmetatalay/aws-serverless-live-streaming

开源协议:Apache License 2.0

下载


Serverless Live Streaming

This is Live Streaming, VOD and Voting / Comment system which uses React, Amplify and Graphql with Appsync.

Serverless Live Streaming

Getting Started

Install Npm dependencies

  1. $ npm install

Installing the CLI & Initializing a new AWS Amplify Project

Installing the CLI

Next, we’ll install the AWS Amplify CLI and Amplify Video package:

  1. $ npm install -g @aws-amplify/cli
  2. $ npm install -g amplify-category-video

Now we need to configure the CLI with our credentials.

If you’d like to see a video walkthrough of this configuration process, click here.

  1. $ amplify configure
  2. - Specify the AWS Region: us-east-1 || us-west-2 || eu-central-1
  3. - Specify the username of the new IAM user: amplify-cli-user
  4. > In the AWS Console, click Next: Permissions, Next: Tags, Next: Review, & Create User to create the new IAM user. Then, return to the command line & press Enter.
  5. - Enter the access key of the newly created user:
  6. ? accessKeyId: (<YOUR_ACCESS_KEY_ID>)
  7. ? secretAccessKey: (<YOUR_SECRET_ACCESS_KEY>)
  8. - Profile Name: amplify-cli-user

Initializing Amplify

  1. $ amplify init
  2. - Enter a name for the project: serverlesslivestream
  3. - Enter a name for the environment: dev
  4. - Choose your default editor: Visual Studio Code (or your default editor)
  5. - Please choose the type of app that youre building: javascript
  6. - What javascript framework are you using: react
  7. - Source Directory Path: src
  8. - Distribution Directory Path: build
  9. - Build Command: npm run-script build
  10. - Start Command: npm run-script start
  11. - Do you want to use an AWS profile? Y
  12. - Please choose the profile you want to use: amplify-cli-user

The Amplify CLI has iniatilized a new project & you will see a new folder: amplify & a new file called aws-exports.js in the src directory. These files hold your project configuration.

To view the status of the amplify project at any time, you can run the Amplify status command:

  1. $ amplify status

To view the amplify project in the Amplify console at any time, run the console command:

  1. $ amplify console

Adding a Cognito Authentication

To add a Cognito for User Authentication, we can use the following command:

  1. $ amplify add auth
  2. Do you want to use the default authentication and security configuration: Default configuration
  3. How do you want users to be able to sign in: Username
  4. Do you want to configure advanced settings? (Use arrow keys): No, I am done

Adding a Live Streaming Video

To add a Video for Live Streaming, we can use the following command:

  1. # This command will create S3 bucket for cloudfront logs
  2. $ aws s3 mb s3://<PUT UNIQUE BUCKET NAME>(i.e. serverlesslivestream1234)
  3. $ amplify add video
  4. ? Please select from one of the below mentioned services: Livestream
  5. ? Provide a friendly name for your resource to be used as a label for this category in the project: serverlesslivestream
  6. ? Do you want to modify any advanced video encoding parameters? No
  7. ? Input Security Group: 0.0.0.0/0
  8. ? MediaLive ingest type: MP4_FILE
  9. ? Encoding Profile: FULL (6 renditions)
  10. ? Auto Start: Yes
  11. ? Provide URL to the MP4 file: http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4
  12. ? Where do you want to stream to? MediaPackage
  13. ? Output streaming standards. MediaPackage supports HLS, DASH, MSS, and/or CMAF: HLS
  14. ? Specify catch-up TV window: 86400
  15. ? Create distribution: Yes
  16. ? Cloud Front Price Class: Price Class 100
  17. ? S3 bucket for CloudFront Logs: (Must already exist): <YOUR UNIQUE BUCKET NAME(i.e. serverlesslivestream1234)>
  18. ? S3 Prefix (Folder) for CloudFront logs: cf_logs/

Adding a VOD

To add a Video for Video On Demand, we can use the following command:

  1. $ amplify add video
  2. ? Please select from one of the below mentioned services: Video On Demand (beta)
  3. ? Provide a friendly name for your resource to be used as a label for this category in the project: serverlessvod
  4. ? Select a system-provided encoding template, specify an already-created template name: Default Encoding Template (Apple HLS @ 1080p30)
  5. ? Is this a production enviroment? No
  6. ? Do you want Amplify to create a new GraphQL API to manage your videos? No

Adding an AWS AppSync GraphQL API for Video Replays and Comments

To add a GraphQL API, we can use the following command:

  1. $ amplify add api
  2. ? Please select from one of the below mentioned services: GraphQL
  3. ? Provide API name: serverlesslivestream
  4. ? Choose the default authorization type for the API API key
  5. ? Enter a description for the API key: serverlesslivestream
  6. ? After how many days from now the API key should expire (1-365): 365
  7. ? Do you want to configure advanced settings for the GraphQL API No, I am done.
  8. ? Do you have an annotated GraphQL schema? No
  9. ? Do you want a guided schema creation? Yes
  10. ? What best describes your project: Single object with fields (e.g., Todo with ID, name, description)
  11. ? Do you want to edit the schema now? Yes

The CLI should open this GraphQL schema in your text editor.

amplify/backend/api/serverlesslivestream/schema.graphql

Update the schema to the following:

  1. type Replay @model{
  2. id: ID!
  3. name: String!
  4. url: String!
  5. likes: Int!
  6. dislikes: Int!
  7. comments: [Comment] @connection(name: "ReplayComments")
  8. }
  9. type Comment @model {
  10. id: ID!
  11. content: String
  12. username: String!
  13. replay: Replay @connection(name: "ReplayComments")
  14. }

Deploying the Amplify resources

To deploy the Amplify resources, run the push command:

  1. $ amplify push
  2. All resources copied.
  3. Successfully pulled backend environment dev from the cloud.
  4. Current Environment: dev
  5. | Category | Resource name | Operation | Provider plugin |
  6. | -------- | ---------------------------- | --------- | ----------------- |
  7. | Auth | serverlesslivestream83a2c4e1 | Create | awscloudformation |
  8. | Video | serverlesslivestream | Create | awscloudformation |
  9. | Video | serverlessvod | Create | awscloudformation |
  10. | Api | serverlesslivestream | Create | awscloudformation |
  11. ? Are you sure you want to continue? Y
  12. # You will be walked through the following questions for GraphQL code generation
  13. ? Do you want to generate code for your newly created GraphQL API: Yes
  14. ? Choose the code generation language target: javascript
  15. ? Enter the file name pattern of graphql queries, mutations and subscriptions: src/graphql/**/*.js
  16. ? Do you want to generate/update all possible GraphQL operations - queries, mutations and subscriptions: Yes
  17. ? Enter maximum statement depth [increase from default if your schema is deeply nested]: 2
Update query

Once graphql folder can be created in above step, then add below query to the src/graphql/queries.js

  1. export const getCommentByReplayId = /* GraphQL */ `
  2. query GetCommentByReplayId($id: ID!) {
  3. getReplay(id: $id) {
  4. comments {
  5. items {
  6. id
  7. content
  8. username
  9. createdAt
  10. updatedAt
  11. }
  12. }
  13. }
  14. }
  15. `;

Now the Amplify Video, Auth and Api is deployed and you can start interacting with it!

Some manual actions to forward streaming source to VOD

  • Go to Elemental Medialive console, and select the channel which is created by Amplify, then Stop the channel
  • Add second Output group as Archive
    Channel Create
  • Add the S3 Bucket URLs by created Amplify Video OnDemand module. Go the S3 Console, and get the bucket name.
    Channel Create 2
  • URLs must be started with s3ssl://.
  • Add Audio option in Output of Archive group as well.
    Channel Create 3
  • Finally update the Channel and Start it.
  • Go to S3 Console, and select the input VOD bucket which created by Amplify Video OnDemand module. Then, modify the S3 Event trigger path for delivery prevfx and suffix: .ts files.
    S3 Event

Start the Application

  1. $ npm start

Here is the UI from the app

Serverless Live Streaming
Serverless Live Streaming
Serverless Live Streaming
Serverless Live Streaming

Here is the Mediaconvert Job, triggered by Lambda when Medialive sends streaming to S3.
Mediaconvert