-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add nodejs sample for lambda remote debugging (#205)
* migrate the lambda remote debugging files to python directory * add the nodejs sample
- Loading branch information
1 parent
af651db
commit dd6939a
Showing
15 changed files
with
147 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ node_modules/ | |
.classpath | ||
.project | ||
.settings/ | ||
.vscode/ | ||
target/ | ||
|
||
.idea/ | ||
|
15 changes: 15 additions & 0 deletions
15
lambda-mounting-and-debugging/javascript/.vscode/launch.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"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" | ||
}, | ||
] | ||
} |
10 changes: 10 additions & 0 deletions
10
lambda-mounting-and-debugging/javascript/.vscode/tasks.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"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;" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# 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' \ | ||
LAMBDA_REMOTE_DOCKER=0 \ | ||
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. |
18 changes: 18 additions & 0 deletions
18
lambda-mounting-and-debugging/javascript/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: "3.8" | ||
|
||
services: | ||
localstack: | ||
container_name: "${LOCALSTACK_DOCKER_NAME-localstack_main}" | ||
image: localstack/localstack: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_REMOTE_DOCKER=0 | ||
- 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
exports.handler = async (event) => { | ||
console.log(event); | ||
const response = { | ||
statusCode: 200, | ||
body: "ok", | ||
}; | ||
return response; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/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"}' |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,4 @@ | |
] | ||
} | ||
] | ||
} | ||
} |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
lambda-mounting-and-debugging/README.md → ...a-mounting-and-debugging/python/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes