Giter Site home page Giter Site logo

sample_simple_websockets_chat_app's Introduction

sample_simple_websockets_chat_app

This repository is a Rust implementation of aws-samples/simple-websockets-chat-app.

Build Environment

The execution environment is assumed to be provided.al2 (Amazon Linux 2)/arm64. Therefore, the default build target is aarch64-unknown-linux-musl. If you are building on macOS, use FiloSottile/homebrew-musl-cross or emk/rust-musl-builder.

Build

Packages are built for each of API Gateway's default websocket routes and custom routes.

# Build all packages
cargo build --release --workspace

# Build per package
cargo build --release --package <package_name>

Deployment

ws_sendmessage

Set the following environment variables. The environment variables can also be obtained from the WebSocket URL (no need to set AWS_REGION).

wss://{AWS_API_ID}.execute-api.{AWS_REGION}.amazonaws.com/{AWS_STAGE}

AWS_API_ID
AWS_STAGE
DYNAMO_TABLE_NAME

DynamoDB

The partition key for the DynamoDB table should be set as connectionId.

IAM

Configure the Execution role of Lambda functions as follows:

Permissions

Grant the following permissions to enable access to the related services:

  • AmazonAPIGatewayInvokeFullAccess
  • AmazonDynamoDBFullAccess
  • AWSXRayDaemonWriteAccess
  • AWSLambdaBasicExecutionRole

Trust relationships

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "lambda.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

Testing the chat API

To test the WebSocket API, you can use wscat, an open-source command line tool.

  1. Install NPM.
  2. Install wscat:
$ npm install -g wscat
  1. On the console, connect to your published API endpoint by executing the following command:
$ wscat -c wss://{YOUR-API-ID}.execute-api.{YOUR-REGION}.amazonaws.com/{STAGE}
  1. To test the sendMessage function, send a JSON message like the following example. The Lambda function sends it back using the callback URL:
$ wscat -c wss://{YOUR-API-ID}.execute-api.{YOUR-REGION}.amazonaws.com/prod
connected (press CTRL+C to quit)
> {"action":"sendmessage", "data":"hello world"}
< hello world

sample_simple_websockets_chat_app's People

Contributors

sundaycrafts avatar

Watchers

 avatar  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.