Skip to content

Apresentação no The Developer's Conference 2023 edição Business, na trilha Node.JS.

License

Notifications You must be signed in to change notification settings

GuinaCosta/multi-region-websocket-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TheDevConf - Trilha Node.js - Feitiçaria ou tecnologia: Websockets com Node.js mas sem servidores?

Este conteúdo foi adaptado do blog da AWS, Building serverless multi-Region WebSocket APIs, e complementado para apresentação no The Developer's Conference 2023 edição Business, na trilha Node.JS.

Solution Overview

Repositório para deploy do WebApp: https://github.com/GuinaCosta/react-websocket

Diagram

Prerequisites

Let’s get you started

1. Make sure you completed the prerequisites above and cloned this repo.

git clone [email protected]:GuinaCosta/multi-region-websocket-api.git

2. Open the repository in your preferred IDE and familiarize yourself with the structure of the project.

.
├── cdk             CDK code that defines our environment
├── img             Architecture image
└── src
    └── lambda      Handler code of the lambda function used to distribute the Lambda layer

3. Install dependencies

node.js dependencies are declared in a package.json. This project contains a package.json file in two different folder:

  • cdk: Dependencies required to deploy your stack with the CDK
  • src: Dependencies required for the Lambda function, i.e. TypeScript types for AWS SDK

Navigate to each of the folders and run npm install

4. Configure your stack (optional)

Open cdk/bin/websockets-tdc.ts and adjust the Regions to deploy the application.

// List of Region codes to deploy the application to
const regionsToDeploy = ['us-west-1', 'eu-west-1', 'ap-northeast-1'];

5. Deploy your application

Navigate to the cdk folder and run the following commands.

cdk synth will synthesize a CloudFormation template from your CDK code. If you haven't worked with CDK in your account before, you need to bootstrap the required resources for the CDK with cdk bootstrap, otherwise skip this step. Note that bootstrapping needs to be performed in every Region you plan to deploy to. You can then deploy the template with cdk deploy.

cdk synth 
# replace account id and Region codes
cdk bootstrap 123456789012/us-east-1 123456789012/eu-west-1 
cdk deploy --all

6. Test the application

Connect to the Websocket API Gateway endpoints in each Region with a Websocket client or command line tool. After connecting, send a message from one of the connected clients. Your message will be send to every other client in the same Region and all clients in other Regions.

Cleaning up

When you are done, make sure to clean everything up.

Run the following command to shut down the resources created in this workshop.

cdk destroy --all

Security

See CONTRIBUTING for more information.

License

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

Event Bus Sample

Source: TransactionApplication
Type: TransactionMessageReceived
Data: { 
  "chatId": "DEFAULT",
  "message": "{\"product\":\"{\\\"productId\\\":\\\"220c00a5-6290-4b14-a8aa-7ca0807bc1ae\\\",\\\"value\\\":97.78622027827524}\"}",
  "senderConnectionId": "XXXX8888"
}	

About

Apresentação no The Developer's Conference 2023 edição Business, na trilha Node.JS.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Languages

  • TypeScript 93.5%
  • JavaScript 6.5%