GithubHelp home page GithubHelp logo

isabella232 / serverless-chat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from claudiajs/serverless-chat

0.0 0.0 0.0 29 KB

Abusing AWS IOT Gateway to create a serverless chat system

JavaScript 79.92% HTML 19.72% CSS 0.36%

serverless-chat's Introduction

Serverless chat

This is an example project showing how to abuse AWS IOT Gateway to create a massively-scalable online chat system using a static HTML page.

IOT Gateway supports websockets, which can be used to connect browsers directly to a message queue, and send/receive messages connected to hierarchical topics. In this case, we're allowing anonymous users to subscribe to any topic starting with /chat/ (check the unauthenticated policy for more information. The security is enforced using normal AWS IAM policies, and provided through AWS Cognito authentication, which allows us to assign IAM policies to unauthenticated users.

The result is that chat allows anonymous users to access exchange messages through hierarchical chat topics, without any active server components we need to maintain.

Prerequisites

Find your aws gateway name:

aws iot describe-endpoint --query endpointAddress --output text

Create a Cognito Identity Pool for Federated Identities (not a Cognito User Pool).

For unauthenticated access, do the following when creating the identity pool:

  • enable access to unauthenticated identities
  • no need to attach authentication providers
  • on 'Your Cognito identities require access to your resources' screen open up the 'Show details' dropdown and adjust role names if you want
  • go to IAM, then add the unauthenticated policy to your unauthenticated access role

Configuring

  1. create ./env/<ENV NAME>.json for your environment, with
{
  "iotGatewayName": "<YOUR IOT GATEWAY NAME>",
  "cognitoIdentityPoolId": "<YOUR COGNITO IDENTITY POOL ID>"
}

Building for development usagw

  1. create dev.json in ./env as described in the Configuring section
  2. npm run rebuild
  3. npm run serve-dev

Building for production usage

  1. create production.json in ./env
  2. npm run rebuild --serverless-chat:buildenv=production
  3. upload the site folder somewhere

Posting an update directly to the gateway

Check out the src/util/post-message.js to see how you can also post messages directly to chat channels (eg a system notification, or replying to messages from a Lambda function.

TODO

  1. Add sender info
  2. authenticated access
  3. automated config
  4. Connection keep-alive/reconnect

More info

serverless-chat's People

Contributors

gojko avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.