66 order : 3
77---
88
9+ import { Tabs , TabItem } from ' @astrojs/starlight/components' ;
10+
911# Overview
1012
1113This guide covers remote debugging of Lambda functions with the IDEs [ Visual Studio Code] ( https://code.visualstudio.com/ ) and [ IntelliJ IDEA] ( https://www.jetbrains.com/idea/ ) .
@@ -21,17 +23,17 @@ More examples and tooling support for local Lambda debugging (including support
2123* [ Lambda Debug Mode (preview)] ( #lambda-debug-mode-preview )
2224* [ Resources] ( #resources )
2325
24- {{< callout tip >}}
26+ :::note
2527Due to the ports published by the Lambda container for the debugger, it is currently only possible to debug one Lambda function at a time.
26- For advanced debugging scenarios, such as those requiring multiple ports, refer to [ Lambda Debug Mode (preview)] ({{< relref "debugging #lambda-debug-mode-preview" >}} ) section.
27- {{< /callout >}}
28+ For advanced debugging scenarios, such as those requiring multiple ports, refer to [ Lambda Debug Mode (preview)] ( #lambda-debug-mode-preview ) section.
29+ :::
2830
2931## Debugging Python lambdas
3032
3133Lambda functions debugging used to be a difficult task.
3234LocalStack changes that
3335with the same local code mounting functionality that also helps you
34- to [ iterate quickly over your function code] ({{< ref "user-guide/ lambda-tools" >}} ).
36+ to [ iterate quickly over your function code] ( /aws/tooling/ lambda-tools/hot-reloading ) .
3537
3638For a simple working example of this feature, you can refer to
3739[ our samples] ( https://github.com/localstack/localstack-pro-samples/tree/master/lambda-mounting-and-debugging ) .
@@ -41,11 +43,11 @@ There, the necessary code fragments for enabling debugging are already present.
4143
4244#### Configure LocalStack for VS Code remote Python debugging
4345
44- First, make sure that LocalStack is started with the following configuration (see the [ Configuration docs] ({{< ref " configuration#lambda" >}} ) for more information):
46+ First, make sure that LocalStack is started with the following configuration (see the [ Configuration docs] ( /aws/capabilities/config/ configuration#lambda) for more information):
4547
46- {{< command >}}
47- $ LAMBDA_DOCKER_FLAGS='-p 19891:19891' localstack start
48- {{< /command >}}
48+ ``` bash
49+ LAMBDA_DOCKER_FLAGS=' -p 19891:19891' localstack start
50+ ```
4951
5052#### Preparing your code
5153
@@ -116,7 +118,7 @@ Make sure to set a breakpoint in the Lambda handler code first, which can then l
116118
117119The screenshot below shows the triggered breakpoint with our ` 'Hello from LocalStack!' ` in the variable inspection view:
118120
119- <!-- ! [Visual Studio Code debugging](vscode-debugging-py-1.png) -->
121+ ! [ Visual Studio Code debugging] ( /images/aws/ vscode-debugging-py-1.png)
120122
121123#### Current Limitations
122124
@@ -137,7 +139,7 @@ You can [follow the steps in the official docs](https://www.jetbrains.com/help/p
137139* Add path mapping with your project files on the host and map it to the remote directory ` /var/task ` .
138140* Copy the ` pip install ` command, and make sure to install the correct ` pydevd-pycharm ` version for your PyCharm IDE.
139141
140- <!-- ! [PyCharm Professional Remote Debugging Configuration](pycharm_remote_debugging.png) -->
142+ ! [ PyCharm Professional Remote Debugging Configuration] ( /images/aws/ pycharm_remote_debugging.png)
141143
142144#### Preparing your code
143145
@@ -171,7 +173,7 @@ def wait_for_debug_client():
171173In the next step we create our function.
172174In order to debug the function in PyCharm set a breakpoint in your function, run the Remote Debug configuration and then invoke the function.
173175
174- <!-- ! [PyCharm Professional debugging](pycharm_lambda_debugging.png) -->
176+ ! [ PyCharm Professional debugging] ( /images/aws/ pycharm_lambda_debugging.png)
175177
176178### Creating the Lambda function
177179
@@ -183,34 +185,34 @@ To create the Lambda function, you just need to take care of two things:
183185
184186So, in our [ example] ( https://github.com/localstack/localstack-pro-samples/tree/master/lambda-mounting-and-debugging ) , this would be:
185187
186- {{< command >}}
187- $ awslocal lambda create-function --function-name my-cool-local-function \
188+ ``` bash
189+ awslocal lambda create-function --function-name my-cool-local-function \
188190 --code S3Bucket=" hot-reload" ,S3Key=" $( pwd) /" \
189191 --handler handler.handler \
190192 --runtime python3.8 \
191193 --timeout 150 \
192194 --role arn:aws:iam::000000000000:role/lambda-role
193- {{< /command >}}
195+ ```
194196
195197We can quickly verify that it works by invoking it with a simple payload:
196198
197- {{< tabpane text=true persist=false >}}
198- {{% tab header ="AWS CLI v1" lang="shell" %}}
199- {{< command >}}
200- $ awslocal lambda invoke --function-name my-cool-local-function \
199+ < Tabs >
200+ < TabItem label = " AWS CLI v1" >
201+ ``` bash
202+ awslocal lambda invoke --function-name my-cool-local-function \
201203 --payload ' {"message": "Hello from LocalStack!"}' \
202204 output.txt
203- {{< /command >}}
204- {{% /tab %}}
205- {{% tab header ="AWS CLI v2" lang="shell" %}}
206- {{< command >}}
207- $ awslocal lambda invoke --function-name my-cool-local-function \
205+ ```
206+ </ TabItem >
207+ < TabItem label = " AWS CLI v2" >
208+ ``` bash
209+ awslocal lambda invoke --function-name my-cool-local-function \
208210 --cli-binary-format raw-in-base64-out \
209211 --payload ' {"message": "Hello from LocalStack!"}' \
210212 output.txt
211- {{< /command >}}
212- {{% /tab %}}
213- {{< /tabpane >}}
213+ ```
214+ </ TabItem >
215+ </ Tabs >
214216
215217## Debugging JVM lambdas
216218
@@ -231,15 +233,15 @@ services:
231233
232234When creating your Lambda function, set the ` _JAVA_OPTIONS` environment variable like so:
233235
234- {{< command >}}
235- $ awslocal lambda create-function --function-name debugfunc \
236- --zip-file fileb://java-handler.zip \
237- --handler myindex.handler \
238- --runtime java8.al2 \
239- --timeout 150 \
240- --role arn:aws:iam::000000000000:role/lambda-role \
241- --environment '{"Variables" : {"_JAVA_OPTIONS": "-Xshare:off -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=0.0.0.0:5050"}}'
242- {{< /command >}}
236+ ` ` ` bash
237+ awslocal lambda create-function --function-name debugfunc \
238+ --zip-file fileb://java-handler.zip \
239+ --handler myindex.handler \
240+ --runtime java8.al2 \
241+ --timeout 150 \
242+ --role arn:aws:iam::000000000000:role/lambda-role \
243+ --environment '{"Variables": {"_JAVA_OPTIONS": "-Xshare:off -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=0.0.0.0:5050"}}'
244+ ` ` `
243245
244246Note the `suspend=y` option here, it will delay code execution until the debugger is attached to the debugger server.
245247If you want to change that, simply switch to `suspend=n`.
@@ -256,13 +258,13 @@ the following content:
256258while [[ -z $(docker ps | grep :5050) ]]; do sleep 1; done
257259` ` `
258260
259- <!-- ! [Run/Debug Configurations](inteliji-debugging-jvm-1.png) -->
261+ ! [Run/Debug Configurations](/images/aws/ inteliji-debugging-jvm-1.png)
260262
261263This shell script should simplify the process a bit since the debugger server is not immediately available (only once Lambda container is up).
262264
263265Then create a new `Remote JVM Debug` configuration and use the script from above as a `Before launch` target :
264266
265- <!-- ! [Run/Debug Configurations](inteliji-debugging-jvm-2.png) -->
267+ ! [Run/Debug Configurations](/images/aws/ inteliji-debugging-jvm-2.png)
266268
267269Now to debug your Lambda function, simply click on the `Debug` icon with `Remote JVM on LS Debug` configuration selected, and then invoke your Lambda function.
268270
@@ -391,36 +393,37 @@ exports.handler = async (event) => {
391393` ` `
392394
393395Create the lambda function using :
394- {{< command >}}
395- $ awslocal lambda create-function --function-name func1 \
396+
397+ ` ` ` bash
398+ awslocal lambda create-function --function-name func1 \
396399 --code S3Bucket="hot-reload",S3Key="$(pwd)/" \
397400 --handler myindex.handler \
398401 --runtime nodejs14.x \
399402 --timeout 150 \
400403 --role arn:aws:iam::000000000000:role/lambda-role
401- {{< /command >}}
404+ ` ` `
402405
403406Now to debug your lambda function, click on the `Debug` icon with
404407` Attach to Remote Node.js` configuration selected, and then invoke your
405408lambda function :
406409
407- {{< tabpane text=true persist=false >}}
408- {{% tab header ="AWS CLI v1" lang="shell" %}}
409- {{< command >}}
410- $ awslocal lambda invoke --function-name func1 \
410+ <Tabs>
411+ <TabItem label ="AWS CLI v1">
412+ ` ` ` bash
413+ awslocal lambda invoke --function-name func1 \
411414 --payload '{"hello":"world"}' \
412415 output.txt
413- {{< /command >}}
414- {{% /tab %}}
415- {{% tab header ="AWS CLI v2" lang="shell" %}}
416- {{< command >}}
417- $ awslocal lambda invoke --function-name func1 \
416+ ` ` `
417+ </TabItem>
418+ <TabItem label ="AWS CLI v2">
419+ ` ` ` bash
420+ awslocal lambda invoke --function-name func1 \
418421 --cli-binary-format raw-in-base64-out \
419422 --payload '{"hello":"world"}' \
420423 output.txt
421- {{< /command >}}
422- {{% /tab %}}
423- {{< /tabpane >}}
424+ ` ` `
425+ </TabItem>
426+ </Tabs>
424427
425428# # Lambda Debug Mode (Preview)
426429
@@ -437,11 +440,11 @@ giving developers ample time to connect remote debuggers and inspect the functio
437440
438441To enable Lambda Debug Mode, set the `LAMBDA_DEBUG_MODE` environment variable as shown below :
439442
440- {{< command >}}
443+ ` ` ` bash
441444LAMBDA_DEBUG_MODE=1 \
442445LAMBDA_DOCKER_FLAGS='-p 19891:19891' \
443446localstack start
444- {{< /command >}}
447+ ` ` `
445448
446449When enabled, Lambda Debug Mode automatically adjusts timeouts to accommodate debugging needs :
447450* **Lambda Container Startup Timeout**: Provides additional time for debugger connection during container creation.
@@ -457,13 +460,16 @@ Manually setting `LAMBDA_DOCKER_FLAGS` is unnecessary when using this configurat
457460
458461Here is an example of mounting a `debug_config.yaml` in your LocalStack container to start your Debug Mode :
459462
460- {{< tabpane >}}
461- {{< tab header="LocalStack CLI" lang="shell" >}}
463+ <Tabs>
464+ <TabItem label="LocalStack CLI">
465+ ` ` ` bash
462466LOCALSTACK_LAMBDA_DEBUG_MODE=1 \
463467LOCALSTACK_LAMBDA_DEBUG_MODE_CONFIG_PATH=/tmp/debug_config.yaml \
464468localstack start --volume /path/to/debug-config.yaml:/tmp/lambda_debug_mode_config.yaml
465- {{< /tab >}}
466- {{< tab header="Docker Compose" lang="yaml" >}}
469+ ` ` `
470+ </TabItem>
471+ <TabItem label="Docker Compose">
472+ ` ` ` yaml
467473services:
468474 localstack:
469475 container_name: "${LOCALSTACK_DOCKER_NAME:-localstack-main}"
@@ -481,8 +487,9 @@ services:
481487 - "./debug_config.yaml:/tmp/debug_config.yaml"
482488 - "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
483489 - "/var/run/docker.sock:/var/run/docker.sock"
484- {{< /tab >}}
485- {{< /tabpane >}}
490+ ` ` `
491+ </TabItem>
492+ </Tabs>
486493
487494Any change to the configuration file on your local filesystem would be automatically picked by the LocalStack container.
488495After debugging a Lambda function, its associated container will automatically stop.
0 commit comments