This sample provides a CDK project that allows you to deploy a serverless chat application based on API Gateway's WebSocket-based API feature.
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 NET8. The frontend is written using Angular 17.
:warning: WARNING :warning: The NET8 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.
TS | NET8 | Feature description |
---|---|---|
:white_check_mark: | :white_check_mark: | "One-click" serverless deployment using AWS CDK |
:white_check_mark: | :white_check_mark: | Infrastructure is split into 6 interdependent stacks (Authorization, Database, REST API, Websocket API, Frontend, Observability) |
:white_check_mark: | :white_check_mark: | Secure HTTPS connection and content delivery using Amazon Cloudfront |
:white_check_mark: | :white_check_mark: | Built-in authentication using Amazon Cognito |
:white_check_mark: | :white_check_mark: | Built-in REST API authorization using Cognito UserPool Authorizer |
:white_check_mark: | :white_check_mark: | Synchronous real-time messaging using API Gateway Websocket API |
:white_check_mark: | :white_check_mark: | Asynchronous user status updates using Amazon SQS and API Gateway Websocket API |
:white_check_mark: | :white_check_mark: | Environment-agnostic Single Page Application frontend (dynamic environment configuration loading) |
:white_check_mark: | :white_check_mark: | Complete request tracing using AWS X-Ray |
:white_check_mark: | :white_check_mark: | Lambda Powertools integration |
:white_check_mark: | :white_check_mark: | Structured logging and monitoring using Amazon Cloudwatch |
:white_check_mark: | :white_check_mark: | Custom metrics & Cloudwatch dashboard |
:white_check_mark: | :x: | Built-in infrastructure security check using CDK-NAG |
The infrastructure backend has been split into two directories (infrastructure-ts
, infrastructure-dotnet
). 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.
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:
:warning: WARNING :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.
cd UI
npm install
ng build --prod
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.
Run the following command in the relevant infrastructure directory to delete the cloudformation stacks:
cdk destroy --all
The backend is fully instrumented using AWS Xray and Lambda Powertools for TypeScript (beta).
The backend outputs 3 custom metrics from the websocket API backend:
The Observability Stack (TS / NET8) creates a custom Cloudwatch Dashboard where these metrics are visualised.
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.
You can find a more detailed description of what the API handler functions are doing here.
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.