Skip to content

aws-samples/multi-region-websocket-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Building serverless multi-Region WebSocket APIs with Amazon API Gateway, AWS Lambda and Amazon DynamoDB

This repository contains the full source code that is used in the blog post Building serverless multi-Region WebSocket APIs.

Solution Overview

Diagram

Prerequisites

Let’s get you started

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

git clone git@github.com:aws-samples/multi-region-websocket-api

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-blog.ts and adjust the Regions to deploy the application.

// List of Region codes to deploy the application to
const regionsToDeploy = ['us-east-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.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •