diff --git a/README.md b/README.md index 61b918d..d3d5368 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ Some of the samples require LocalStack Pro features. Please make sure to properl | [Cognito with JWT](cognito-jwt) | Running Cognito authentication and user pools locally | | [Transfer API with S3](transfer-ftp-s3) | Using the Transfer API to upload files to S3 | | [Codecommit with Git repository](codecommit-git-repo) | Using the Codecommit API to create and push to a Git repository | -| [Lambda Mounting and Debugging](lambda-mounting-and-debugging) | Debugging Lambda functions locally | | [Lambda Debugging SAM Java](lambda-debugging-sam-java) | Debugging Java Lambda functions using AWS SAM | | [Lambda Debugging SAM JavaScript](lambda-debugging-sam-javascript) | Debugging JavaScript Lambda functions using AWS SAM | | [Lambda Debugging SAM Python](lambda-debugging-sam-python) | Debugging Python Lambda functions using AWS SAM | diff --git a/lambda-mounting-and-debugging/javascript/.vscode/launch.json b/lambda-mounting-and-debugging/javascript/.vscode/launch.json deleted file mode 100644 index 790810c..0000000 --- a/lambda-mounting-and-debugging/javascript/.vscode/launch.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "address": "127.0.0.1", - "localRoot": "${workspaceFolder}", - "name": "Attach to Remote Node.js", - "port": 9229, - "remoteRoot": "/var/task/", - "request": "attach", - "type": "node", - "preLaunchTask": "Wait Remote Debugger Server" - }, - ] -} diff --git a/lambda-mounting-and-debugging/javascript/.vscode/tasks.json b/lambda-mounting-and-debugging/javascript/.vscode/tasks.json deleted file mode 100644 index 101dfbc..0000000 --- a/lambda-mounting-and-debugging/javascript/.vscode/tasks.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "Wait Remote Debugger Server", - "type": "shell", - "command": "while [[ -z $(docker ps | grep :9229) ]]; do sleep 1; done; sleep 1;" - } - ] -} diff --git a/lambda-mounting-and-debugging/javascript/Makefile b/lambda-mounting-and-debugging/javascript/Makefile deleted file mode 100644 index 95b14e0..0000000 --- a/lambda-mounting-and-debugging/javascript/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -VENV_DIR ?= .venv - -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -install: ## Install dependencies - @which awslocal || pip install awscli-local - test -e $(VENV_DIR) || virtualenv $(VENV_DIR) - . $(VENV_DIR)/bin/activate; pip install debugpy - -run: ## Deploy and invoke the Lambda container locally - echo "Deploying Lambda locally"; \ - ./run.sh; \ - echo "Done - test successfully finished." - -start: - docker-compose up -d - -stop: - @echo - localstack stop -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -.PHONY: usage install start run stop ready logs test-ci diff --git a/lambda-mounting-and-debugging/javascript/README.md b/lambda-mounting-and-debugging/javascript/README.md deleted file mode 100644 index d88db2b..0000000 --- a/lambda-mounting-and-debugging/javascript/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# LocalStack Demo: Lambda Code Mounting and Debugging - -Simple demo application to illustrate debugging NodeJS Lambdas locally. - -## Prerequisites - -* LocalStack -* Docker -* `make` -* [`awslocal`](https://github.com/localstack/awscli-local) - -## Installation - -To install the dependencies: - -```sh -make install -``` - -## Starting Up - -You can start LocalStack with Docker Compose: - -```sh -docker-compose up -d -``` - -Alternatively, you can use the following `localstack` CLI configuration: - -```sh -LAMBDA_DOCKER_FLAGS='-e NODE_OPTIONS=--inspect-brk=0.0.0.0:9229 -p 9229:9229' \ - localstack start -d -``` - -## Running the sample - -The project ships with a Visual Studio Code debug launch config (see `.vscode/launch.json`). This configuration can be used to attach to the code in the Lambda function while it is executing. - -The following command deploys the Lambda and finally invoke the Lambda locally: - -```sh -make run -``` - -# License - -The code in this sample is available under the Apache 2.0 license. diff --git a/lambda-mounting-and-debugging/javascript/docker-compose.yml b/lambda-mounting-and-debugging/javascript/docker-compose.yml deleted file mode 100644 index 94cb778..0000000 --- a/lambda-mounting-and-debugging/javascript/docker-compose.yml +++ /dev/null @@ -1,17 +0,0 @@ -version: "3.8" - -services: - localstack: - container_name: "${LOCALSTACK_DOCKER_NAME-localstack-main}" - image: localstack/localstack-pro:latest - ports: - - "127.0.0.1:4566:4566" # LocalStack Gateway - - "127.0.0.1:4510-4559:4510-4559" # external services port range - environment: - - DEBUG=1 - - LAMBDA_DOCKER_FLAGS=-e NODE_OPTIONS=--inspect-brk=0.0.0.0:9229 -p 9229:9229 - - LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR-} - - DOCKER_HOST=unix:///var/run/docker.sock - volumes: - - "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack" - - "/var/run/docker.sock:/var/run/docker.sock" diff --git a/lambda-mounting-and-debugging/javascript/function.js b/lambda-mounting-and-debugging/javascript/function.js deleted file mode 100644 index 7506b07..0000000 --- a/lambda-mounting-and-debugging/javascript/function.js +++ /dev/null @@ -1,8 +0,0 @@ -exports.handler = async (event) => { - console.log(event); - const response = { - statusCode: 200, - body: "ok", - }; - return response; -}; diff --git a/lambda-mounting-and-debugging/javascript/run.sh b/lambda-mounting-and-debugging/javascript/run.sh deleted file mode 100755 index 41ce712..0000000 --- a/lambda-mounting-and-debugging/javascript/run.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -awslocal lambda create-function \ - --function-name localstack-nodejs-lambda-function \ - --code S3Bucket="hot-reload",S3Key="$(pwd)/" \ - --handler function.handler \ - --runtime nodejs14.x \ - --timeout 120 \ - --role arn:aws:iam::000000000000:role/lambda-role - -awslocal lambda invoke \ - --function-name localstack-nodejs-lambda-function test.lambda.log \ - --cli-binary-format raw-in-base64-out \ - --payload '{"hello":"world"}' diff --git a/lambda-mounting-and-debugging/python/.gitignore b/lambda-mounting-and-debugging/python/.gitignore deleted file mode 100644 index bf0824e..0000000 --- a/lambda-mounting-and-debugging/python/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.log \ No newline at end of file diff --git a/lambda-mounting-and-debugging/python/.vscode/launch.json b/lambda-mounting-and-debugging/python/.vscode/launch.json deleted file mode 100644 index 8e7e21a..0000000 --- a/lambda-mounting-and-debugging/python/.vscode/launch.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Python: Remote Attach", - "type": "python", - "request": "attach", - "connect": { - "host": "localhost", - "port": 19891 - }, - "pathMappings": [ - { - "localRoot": "${workspaceFolder}", - "remoteRoot": "." - } - ] - } - ] -} diff --git a/lambda-mounting-and-debugging/python/Makefile b/lambda-mounting-and-debugging/python/Makefile deleted file mode 100644 index 33a99cb..0000000 --- a/lambda-mounting-and-debugging/python/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -export AWS_ACCESS_KEY_ID ?= test -export AWS_SECRET_ACCESS_KEY ?= test -export AWS_DEFAULT_REGION = us-east-1 -VENV_DIR ?= .venv - -usage: ## Show this help - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' - -install: ## Install dependencies - @which awslocal || pip install awscli-local - test -e $(VENV_DIR) || virtualenv $(VENV_DIR) - . $(VENV_DIR)/bin/activate; pip install debugpy - -run: ## Deploy and invoke the Lambda container locally - echo "Deploying Lambda locally"; \ - ./run.sh; \ - echo "Done - test successfully finished." - -start: - localstack start -d - -stop: - @echo - localstack stop -ready: - @echo Waiting on the LocalStack container... - @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1) - -logs: - @localstack logs > logs.txt - -test-ci: - make start install ready run; return_code=`echo $$?`;\ - make logs; make stop; exit $$return_code; - -.PHONY: usage install start run stop ready logs test-ci - diff --git a/lambda-mounting-and-debugging/python/README.md b/lambda-mounting-and-debugging/python/README.md deleted file mode 100644 index ece33f9..0000000 --- a/lambda-mounting-and-debugging/python/README.md +++ /dev/null @@ -1,71 +0,0 @@ -# LocalStack Demo: Lambda Code Mounting and Debugging - -Simple demo application to illustrate debugging Python Lambdas locally. - -## Prerequisites - -* LocalStack -* Docker -* `make` -* [`awslocal`](https://github.com/localstack/awscli-local) - -## Installing - -To install the dependencies: -``` -make install -``` - -## Starting Up - -Make sure that LocalStack is started with the following configuration: -``` -LOCALSTACK_AUTH_TOKEN=... \ - LAMBDA_DOCKER_FLAGS='-p 19891:19891' \ - DEBUG=1 localstack start -``` - -The config option `LAMBDA_DOCKER_FLAGS='-p 19891:19891'` defines a Docker flag that exposes port `19891` for debugging the Lambda handler code that will run inside the container. - -## Running the Sample - -The project ships with a Visual Studio Code debug launch config (see `.vscode/launch.json`). This configuration can be used to attach to the code in the Lambda function while it is executing. - -The following command used to first install the dependencies (e.g., `debugpy`), then deploy, and finally invoke the Lambda locally: - -``` -make run -``` - -### Attaching the VSCode Debugger - -After the Lambda starts, you have about 15 seconds (timeout configurable in the Lambda handler!) to switch to Visual Studio Code and run the preconfigured remote debugger. Make sure to set a breakpoint in the Lambda handler code first, which can then later be inspected. - -The screenshot below shows with the breakpoint selected, including the Lambda event message `'Hello from LocalStack!'`: - - - -### Quick Dev Loop with Lambda Code Mounting - -Note that, since the Lambda code is mounted from your local filesystem into the Lambda container (by means of `hot-reload` as special bucket name in `run.sh`), all changes are immediately reflected. For example, you could change the implementation of the handler as follows: -``` -def handler(event, context): - """Lambda handler that will get invoked by the LocalStack runtime""" - - # wait for the debugger to get attached - wait_for_debug_client() - # print the incoming invocation event - print(event) - - # additional line added below: - print("!! Additional log output !!") -``` -... and then upon next invocation of the Lambda, the additional print output will immediately appear in the Lambda logs. This allows for a quick dev/debug loop, without the need to redeploy the Lambda after the handler is changed! - -## Next Steps - -More examples and tooling support for local Lambda debugging (including support for other IDEs like PyCharm, IntelliJ, etc.) is coming soon - stay tuned! - -## License - -The code in this sample is available under the Apache 2.0 license. diff --git a/lambda-mounting-and-debugging/python/handler.py b/lambda-mounting-and-debugging/python/handler.py deleted file mode 100644 index 145aaeb..0000000 --- a/lambda-mounting-and-debugging/python/handler.py +++ /dev/null @@ -1,31 +0,0 @@ - -def handler(event, context): - """Lambda handler that will get invoked by the LocalStack runtime""" - - # wait for the debugger to get attached - wait_for_debug_client() - # print the incoming invocation event - print(event) - - -def wait_for_debug_client(timeout=15): - """Utility function to enable debugging with Visual Studio Code""" - import time, threading - import sys, glob - sys.path.append(glob.glob(".venv/lib/python*/site-packages")[0]) - import debugpy - - debugpy.listen(("0.0.0.0", 19891)) - class T(threading.Thread): - daemon = True - def run(self): - time.sleep(timeout) - print("Canceling debug wait task ...") - debugpy.wait_for_client.cancel() - T().start() - print("Waiting for client to attach debugger ...") - debugpy.wait_for_client() - - -if __name__ == "__main__": - handler({}, {}) diff --git a/lambda-mounting-and-debugging/python/run.sh b/lambda-mounting-and-debugging/python/run.sh deleted file mode 100755 index 8cb8288..0000000 --- a/lambda-mounting-and-debugging/python/run.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -awslocal lambda create-function --function-name func1 --timeout 60 --code "S3Bucket=hot-reload,S3Key=$(pwd)/" --handler handler.handler --role arn:aws:iam::000000000000:role/test-role --runtime python3.9 -awslocal lambda invoke --function-name func1 test.lambda.log --payload '{"message":"Hello from LocalStack!"}' diff --git a/lambda-mounting-and-debugging/python/vscode-debugging.png b/lambda-mounting-and-debugging/python/vscode-debugging.png deleted file mode 100644 index f1e65ff..0000000 Binary files a/lambda-mounting-and-debugging/python/vscode-debugging.png and /dev/null differ