{"id":16466145,"url":"https://github.com/isystk/lambda-websocket-template","last_synced_at":"2025-09-04T15:44:05.730Z","repository":{"id":149292264,"uuid":"526549550","full_name":"isystk/lambda-websocket-template","owner":"isystk","description":"AWS（API Gateway → Lambda → DynamoDB）を利用したWebSocketのサンプルです。 リアルタイムでチャットするようなアプリケーションの構築が出来ます。 SAM を利用して管理しているので、コマンドひとつでインフラを構築出来るようにしています。 また、Dockerを利用することでローカル環境でも実装・テストが出来るようにしています。","archived":false,"fork":false,"pushed_at":"2022-08-29T07:37:46.000Z","size":32,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-30T19:50:34.037Z","etag":null,"topics":["dynamodb","lambda","websocket"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/isystk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-19T09:46:54.000Z","updated_at":"2022-08-19T09:54:05.000Z","dependencies_parsed_at":"2023-04-05T06:32:56.293Z","dependency_job_id":null,"html_url":"https://github.com/isystk/lambda-websocket-template","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/isystk/lambda-websocket-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isystk%2Flambda-websocket-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isystk%2Flambda-websocket-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isystk%2Flambda-websocket-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isystk%2Flambda-websocket-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/isystk","download_url":"https://codeload.github.com/isystk/lambda-websocket-template/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isystk%2Flambda-websocket-template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273632821,"owners_count":25140770,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dynamodb","lambda","websocket"],"created_at":"2024-10-11T11:36:32.951Z","updated_at":"2025-09-04T15:44:05.697Z","avatar_url":"https://github.com/isystk.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"🌙 lambda-websocket-template\n====\n\n![GitHub issues](https://img.shields.io/github/issues/isystk/lambda-websocket-template)\n![GitHub forks](https://img.shields.io/github/forks/isystk/lambda-websocket-template)\n![GitHub stars](https://img.shields.io/github/stars/isystk/lambda-websocket-template)\n![GitHub license](https://img.shields.io/github/license/isystk/lambda-websocket-template)\n\n## 📗 プロジェクトの概要\n\nAWS（API Gateway → Lambda → DynamoDB）を利用したWebSocketのサンプルです。\nリアルタイムでチャットするようなアプリケーションの構築が出来ます。\nSAM を利用して管理しているので、コマンドひとつでインフラを構築出来るようにしています。\nまた、Dockerを利用することでローカル環境でも実装・テストが出来るようにしています。\n\n## 🌐 Demo\n\nwscat -c wss:///3gphoqfej8.execute-api.ap-northeast-1.amazonaws.com/Prod?roomId=test\n\n## 📦 ディレクトリ構造\n\n```\n.\n├── README.md\n├── app (Lambdaのモジュール)\n│   ├── app.js\n│   ├── data\n│   ├── dynamodb-client.js\n│   ├── lambda.js\n│   ├── local-app.js\n│   ├── node_modules\n│   ├── package-lock.json\n│   ├── package.json\n│   ├── schema\n│   └── tests\n├── dc.sh (Docker管理用のシェルスクリプト)\n├── docker\n│   ├── awscli\n│   ├── docker-compose.yml\n│   └── dynamodb\n├── layers (共通モジュール)\n│   └── app-layer\n├── samconfig.toml\n└── template.yaml\n```\n\n## 🔧 開発環境の構築\n\nIAM ユーザーを用意する\n```\nユーザ名：「lambda-user」\nアクセス権限：\n「AdministratorAccess」\n```\n\nSAM CLI をインストールする\n```\n$ pip install aws-sam-cli\n```\n\nwscat をインストール\n```\nnpm install -g wscat\n```\n\nAWSにアクセスする為の設定を作成する\n```\n$ aws configure --profile lambda-user \nAWS Access Key ID [None]: xxxxxxxxxx\nAWS Secret Access Key [None]: xxxxxxxxxx\nDefault region name [None]: ap-northeast-1\nDefault output format [None]: json\n```\n\n## 🖊️ Docker 操作用シェルスクリプトの使い方\n\n```\nUsage:\n  dc.sh [command] [\u003coptions\u003e]\n\nOptions:\n  stats|st                 Dockerコンテナの状態を表示します。\n  init                     Dockerコンテナ・イメージ・生成ファイルの状態を初期化します。\n  start                    すべてのDaemonを起動します。\n  stop                     すべてのDaemonを停止します。\n  --version, -v     バージョンを表示します。\n  --help, -h        ヘルプを表示します。\n```\n\n## 💬 使い方\n\nローカルでAPIを起動する\n```\n# 事前準備\n$ ./dc.sh init\n$ docker network create lambda-local\n\n# Dockerを起動する\n$ ./dc.sh start\n\n# DynamoDBにテーブルを作成する\n$ ./dc.sh aws local\n\u003e aws dynamodb create-table --cli-input-json file://app/schema/connections.json --endpoint-url http://dynamodb:8000  --billing-mode PAY_PER_REQUEST\n\u003e aws dynamodb create-table --cli-input-json file://app/schema/room.json --endpoint-url http://dynamodb:8000  --billing-mode PAY_PER_REQUEST\n\u003e aws dynamodb list-tables  --endpoint-url http://dynamodb:8000 \n\u003e aws dynamodb scan --table-name simple_websocket_app_posts  --endpoint-url http://dynamodb:8000\n(テーブルを削除する場合)\n\u003e aws dynamodb delete-table --table-name simple_websocket_app_posts --endpoint-url http://dynamodb:8000\n\n# SAMでアプリをビルドしてからAPIを起動する\n$ sam build\n$ sam local start-api --docker-network lambda-local\n\n# ローカルだと動作しないので調査中。。\n\n```\n\n本番環境（AWS） にデプロイする\n```\n# ビルドを実行する（.aws-samディレクトリに生成される）\n$ sam build\n# AWSに反映する\n$ sam deploy --config-env stg\n\n# （ターミナル２つから）ルームに接続してメッセージを送信する\n$ wscat -c wss:///xxxxxx.execute-api.ap-northeast-1.amazonaws.com/Prod?roomId=test\nConnected (press CTRL+C to quit)\n\u003c { \"action\": \"sendmessage\", \"data\": {\"type\": \"test\", \"value\": \"hello world\" }}\n```\n\nAWSから、DynamoDB、Lambda\u0026APIGatewayを削除する\n```\n$ sam delete --stack-name simple-websocket-app --profile lambda-user\n```\n\n### DynamoDBAdmin\nDynamoDBに接続してデータの参照や編集が可能です。\nDockerを起動後に以下のURLにアクセスすると利用可能です。\n\nhttp://localhost:8001/\n\n![DynamoDB-Admin](./dynamodb-admin.png \"WSL-MySQL\")\n\n\n## 🎨 参考\n\n| プロジェクト| 概要|\n| :---------------------------------------| :-------------------------------|\n| [WebSocket - AWS の API Gateway と Lambda でルーム機能付きのchatを作る時の仕様を考える](https://qiita.com/anfangd/items/ebcd77173341b10b3684)| WebSocket - AWS の API Gateway と Lambda でルーム機能付きのchatを作る時の仕様を考える |\n\n## 🎫 Licence\n\n[MIT](https://github.com/isystk/lambda-websocket-template/blob/master/LICENSE)\n\n## 👀 Author\n\n[isystk](https://github.com/isystk)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisystk%2Flambda-websocket-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fisystk%2Flambda-websocket-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisystk%2Flambda-websocket-template/lists"}