Coder Social home page Coder Social logo

alvaromrjack / aws-websocket-chat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aws-samples/websocket-chat-application

0.0 0.0 0.0 4.38 MB

This application provides the CDK project and a frontend that allows you to build a serverless chat application based on API Gateway's WebSocket-based API feature.

License: MIT No Attribution

JavaScript 3.45% C# 42.66% TypeScript 50.35% Makefile 0.06% HTML 1.86% Dockerfile 0.06% SCSS 1.55%

aws-websocket-chat's Introduction

Serverless chat application using ApiGateway Websockets

This project lets you provision a ready-to-use fully serverless real-time chat application using Amazon ApiGateway Websockets. The infrastructure code is using the AWS Cloud Development Kit(AWS CDK) and implemented in both Typescript and NET7. The frontend is written using Angular 15.

⚠️ WARNING ⚠️ The NET7 implementation is still work-in-progress, however it should work as-is and has the same security features implemented as the Typescript version. Below you can find a breakdown of feature implementation state.

Features

TS NET7 Feature description
"One-click" serverless deployment using AWS CDK
Infrastructure is split into 6 interdependent stacks (Authorization, Database, REST API, Websocket API, Frontend, Observability)
Secure HTTPS connection and content delivery using Amazon Cloudfront
Built-in authentication using Amazon Cognito
Built-in REST API authorization using Cognito UserPool Authorizer
Synchronous real-time messaging using API Gateway Websocket API
Asynchronous user status updates using Amazon SQS and API Gateway Websocket API
Environment-agnostic Single Page Application frontend (dynamic environment configuration loading)
Complete request tracing using AWS X-Ray
Lambda Powertools integration (beta)
Structured logging and monitoring using Amazon Cloudwatch
Custom metrics & Cloudwatch dashboard
Built-in infrastructure security check using CDK-NAG

Solution Overview

Project structure

The infrastructure backend has been split into two directories (infrastructure-ts, infrastructure-net). These folders contain language-specific implementations for both the AWS CDK code and the lambda handlers. Please read the Readme file in the relevant directory for specific deployment instructions.

Prerequisites

  • AWS CLI installed and configured with the aws account you want to use.
  • AWS CDK installed and configured with the aws account you want to use.
  • docker installed and is up and running locally (required for the lambda function builds).
  • Angular CLI installed.
  • dotnetcore3.1 installed (for the NET7 infrastructure version)

Security considerations

For the sake of this demo, not all security features are enabled to save cost and effort of setting up a working PoC.

Below you can find a list of security recommendations in case you would like to deploy the infrastructure in a production environment:

  • Currently all registered users can immediately access the application without second factor authentication or account confirmation. This is not suitable for production use. Please change the Cognito configuration to enable e-mail/sms verification and MFA. In a future release this will be addressed with a feature flag to toggle between different authentication modes.
  • The DynamoDB tables have no backups configured by default. Please enable PITR (point-in-time recovery) and table backups. The tables will be removed on cloudformation stack deletion.
  • Logging for the APIGateway API/stage and for the Cloudfront distribution are disabled. Please enable these additional logs in production environments for audit and troubleshooting purposes.
  • The Cloudfront distribution uses the default cloudfront domain and viewer certificate. The default viewer certificate defaults to the TLSv1 protocol. In order to enforce newer protocols, please use a custom domain with a custom certificate and set the MinimumProtocolVersion to TLSv1.2.

Getting started

Deployment

⚠️ WARNING ⚠️ The domain prefix for the Cognito Userpool needs to be globally unique. Before deployment, please make sure to configure your unique domain prefix at the FrontendStack declaration.

For language specific instructions, please check the readme file in the related infrastructure directory.

[Optional] - Building the frontend

  • Change directory to where UI code lives.
    cd UI
  • Restore NPM packages for the project
    npm install
  • Build the frontend application
    ng build --prod

Opening the chat application

The chat application's URL will be found at the Frontend stack's output. Open the Cloudfront Distribution's URL in your browser, where you'll be redirected to the Cognito login/singup page.

Cleanup

Run the following command in the relevant infrastructure directory to delete the cloudformation stacks:

    cdk destroy --all

Observability

The backend is fully instrumented using AWS Xray and Lambda Powertools for TypeScript (beta).

Custom Metrics & Cloudwatch Dashboard

The backend outputs 3 custom metrics from the websocket API backend:

  • New Connections
  • Closed Connections
  • Messages Delivered

The Observability Stack (TS / NET7) creates a custom Cloudwatch Dashboard where these metrics are visualised.

AWS X-Ray and ServiceMap integration

Requests are automatically traced and instrumented using AWS X-Ray. You can use the ServiceMap to visualise the interactions between the backend components and trace latencies, response codes, etc. between these components.

API Handler documentation

You can find a more detailed description of what the API handler functions are doing here.

Found an issue? Anything to add?

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

aws-websocket-chat's People

Contributors

santatamas avatar dependabot[bot] avatar johngreen-dev avatar amerieum avatar amazon-auto avatar yuyokk 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.