Awesome Open Source
Awesome Open Source

Serverless Components

 

Deploy a Full-Stack Realtime App in seconds using Serverless Components. Just provide your frontend code (powered by the website component), and your backend code (powered by the socket component).

Great use-cases for this project are: Chat Apps, Bots, Notification Systems, Charting Dashboards, Stock Tickers & more. As always, consider a serverless stack like this if you are looking to deliver software or features with extremely low overhead.

 

  1. Install
  2. Create
  3. Configure
  4. Deploy
  5. Example
  6. Pricing

 

1. Install

$ npm install -g serverless

2. Create

$ mkdir my-realtime-app && cd my-realtime-app

the directory should look something like this:

|- backend
  |- socket.js
|- frontend
  |- index.html
|- serverless.yml
|- .env      # your AWS api keys

# .env
AWS_ACCESS_KEY_ID=XXX
AWS_SECRET_ACCESS_KEY=XXX

the socket.js file should minimally look something like this:

on('default', async (data, socket) => {
  socket.send(data)
})

For more info on working with the socket.js file, check out the socket component docs.

To see a full example of an application built with this, check out this Chat Application.

3. Configure

# serverless.yml

RealtimeApp:
  component: "@serverless/realtime-app"
  inputs:
    # backend config to be passed to the socket component
    backend:
      code:
        root: ./code # The root folder containing the backend code.
        src: dist # The folder within your 'src' directory containing your built artifacts
        hook: npm run build # A hook to build/test/do anything
      memory: 128
      timeout: 10
      env:
        TABLE_NAME: my-table

    # frontend config to be passed to the website component
    frontend:
      code:
        root: ./ # The root folder of your website project.  Defaults to current working directory
        src: ./src # The folder to be uploaded containing your built artifact
        hook: npm run build # A hook to build/test/do anything to your code before uploading
      env: # Environment variables to include in a 'env.js' file with your uploaded code.
        API_URL: https://api.com
    region: us-east-1

4. Deploy

$ serverless

5. Example

You can see a full Chat Application that uses this Component in the example folder. It leverages AWS DynamoDB to maintain state of who is connected, so that messages can be sent out to the appropriate connection IDs.

You can also see how this Component can be used programmatically in the Chat App Component's source code.

6. Pricing

AWS API Gateway Websockets Pricing https://aws.amazon.com/api-gateway/pricing/#WebSocket_APIs

AWS Lambda Pricing https://aws.amazon.com/lambda/pricing/

 

New to Components?

Checkout the Serverless Components repo for more information.


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
javascript (70,346
aws (1,100
serverless (660
lambda (247
realtime (217