lambda関数追加 - #3
Conversation
Summary of ChangesHello @Koonosuke, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! このプルリクエストは、AWS Lambda関数を導入し、REST API GatewayとAWS IoT Core間のブリッジとして機能させます。この関数は、HTTPリクエストを受信し、その内容を検証した後、指定されたIoTデバイスを制御するためのMQTTメッセージとしてAWS IoT Coreに転送することを目的としています。これにより、外部システムからIoTデバイスへのコマンド発行が容易になります。 Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
🔗 関連するNotionタスク状態: 進行中 |
| //API Gateway → Lambda の body は JSON ではなく "文字列"だからJSON.parse() しないと中の値を取り出せない | ||
| let body; | ||
| try { | ||
| body = JSON.parse(event.body); |
There was a problem hiding this comment.
event.body が null や undefined の場合、JSON.parse はエラーをスローします。現在の実装では catch ブロックで捕捉され、「Invalid JSON in request body」というメッセージで400エラーが返されますが、これは「リクエストボディが空である」という問題とは異なります。
パースする前に event.body の存在をチェックすることで、より的確なエラーメッセージを返すことができます。
if (!event.body) {
return {
statusCode: 400,
body: JSON.stringify({
status: "error",
message: "Request body is missing",
}),
}
}
body = JSON.parse(event.body)| //前者はコンソールとかでいじった証明書の作成など設定をいじるチャンネル | ||
| //後者はMQTT メッセージの通り道→つまりこのlambda関数でやるのは後者 | ||
|
|
||
| const iot = new IoTDataPlaneClient({ region: "ap-northeast-1" }); |
There was a problem hiding this comment.
| // --------------------------- | ||
| // Step 3: Publish 先 Topic | ||
| // --------------------------- | ||
| const topic = `iot/xiao/${deviceId}/control`; |
There was a problem hiding this comment.
| // --------------------------- | ||
| const topic = `iot/xiao/${deviceId}/control`; | ||
|
|
||
| // XIAO が必要な形式(type + payload) |
概要
その他