
2025年7月17日に AWS Lambda の新機能「リモートデバッグ」がリリースされた🎉
実環境にある AWS Lambda 関数に対して,ローカル環境の VS Code (AWS Toolkit for Visual Studio Code) でブレークポイントを設定してデバッグができる.さっそく試す👌
ちなみに現状だと以下のランタイムに限定されているようだった.
- Python (Amazon Linux 2023)
- Java
- JavaScript / Node.js (Amazon Linux 2023)
使いどころ
ドキュメントに Simplify your tests and Lambda functions by separating Lambda-specific code from your core business logic. と書いてある通り,ハンドラからビジネスロジックを呼び出すようにして,ビジネスロジックに対してテストを実行することができるし,関連する依存はモックや LocalStack などのエミュレーターを使って解決することもできる.
しかし Testing in the cloud とも書いてあって,実際に AWS Lambda を実行するときに遭遇するような問題もある.一時的にログを追加して print デバッグをしたという経験もある😇そういうときに今回の「リモートデバッグ」という選択肢が使えそう.
サンプルアプリケーション
今回はサンプルとして AWS Serverless Patterns Collection にある「Amazon SQS Queue to AWS Lambda(Python 実装)」を使う.Amazon SQS キューにメッセージを送信すると AWS Lambda 関数が呼び出されるというシンプルなサーバレスアプリケーションになっている👏
main.tf のリージョン指定を書き換えて terraform apply を実行しておく.準備完了〜❗️
provider "aws" {
- region = "eu-west-1"
+ region = "ap-northeast-1"
}
リモートデバッグを試す
まず,適当なディレクトリで VS Code を立ち上げる.そして AWS Toolkit for Visual Studio Code → Asia Pacific (Tokyo) → Lambda → AWS Lambda 関数(今回は unified-ewe-lambda)を選択して,最後に Invoke Remotely というボタンを押す.

次に Remote invoke configuration という画面で Remote debugging を有効化して✅️ さらに Download remote code というボタンを押してコードを AWS Lambda 関数から取得する.あとはコード上にブレークポイントを設定すれば OK👌
ちなみに以下のような注意点も載っていて,プロダクション環境での利用は非推奨になっている🚨
Remote debugging is not recommended for production environments. The AWS Toolkit modifies your function by deploying it with an additional layer to enable remote debugging.

最後は Sample event にリモートデバッグで使うペイロードを指定する.今回は sam local generate-event sqs receive-message コマンドの結果を参考に以下の JSON を作った.
{ "Records": [ { "messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78", "receiptHandle": "MessageReceiptHandle", "body": "This message is for testing AWS Lambda remote debugging!", "attributes": { "ApproximateReceiveCount": "1", "SentTimestamp": "1523232000000", "SenderId": "123456789012", "ApproximateFirstReceiveTimestamp": "1523232000001" }, "messageAttributes": {}, "md5OfBody": "7bec58bfb630a9448ce1cfec33398eb7", "eventSource": "aws:sqs", "eventSourceARN": "arn:aws:sqs:ap-northeast-1:000000000000:unified-ewe", "awsRegion": "ap-northeast-1" } ] }
そして Remote Invoke ボタンを押すとブレークポイントで止まる🛑うおおおお〜 \( 'ω')/ あとは見慣れた VS Code のデバッグ画面で「変数」や「ウォッチ式」を使ってデバッグできるぞ〜👏

LDKLayer とは
ドキュメントを読むと以下のように書いてある.よって,リモートデバッグ中は一時的な AWS Lambda レイヤーを追加して,さらにタイムアウトも最大まで伸ばすという変更が入ってしまう.確かにこの仕様だとプロダクション環境では基本的には使えないと思う.内部的に AWS IoT セキュアトンネリングが使われているのは「へぇ〜」ポイントだった💡
The AWS Toolkit enables remote debugging by temporarily modifying your Lambda functions with an additional Lambda debugging layer and extending the Lambda invoke timeout limit to 900 seconds. A secure connection is established between your local debugger and the Lambda runtime environment using AWS IoT Secure Tunneling. This connection allows you to use your local-code breakpoints to step through the function as it executes remotely. After your debugging session is complete, all of the temporary modifications are automatically reverted to their original settings.
実際に AWS Lambda 関数を確認したら,ドキュメント通りの状態になっていた.リモートデバッグ用の AWS Lambda レイヤーは東京リージョンだと arn:aws:lambda:ap-northeast-1:435951944084:layer:LDKLayerX86:1 になっていて,LDK という単語は今まで見たことがなく Lambda Debug Kit の略?

ちなみに AWS Toolkit for Visual Studio Code の実装を確認したら,LDKLayer をホスティングする AWS アカウントは packages/core/src/lambda/remoteDebugging/ldkLayers.ts にまとまっていた😀
まとめ
あくまで開発用途だけど AWS Lambda 関数のデバッグをするときに今後は「リモートデバッグ」という選択肢も持っておこう❗️
関連ポスト
これはイイかも❗️Lambda 関数のコードにブレークポイントを付けてリモートデバッグできる機能じゃん \( 'ω')/
— カック (@kakakakakku) 2025年7月19日
AWS Lambda enables developers to debug functions running in the cloud from VS Code IDEhttps://t.co/QShHcEctcu