File tree Expand file tree Collapse file tree 15 files changed +147
-3
lines changed
lambda-mounting-and-debugging Expand file tree Collapse file tree 15 files changed +147
-3
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ node_modules/
44.classpath
55.project
66.settings /
7- .vscode /
87target /
98
109.idea /
Original file line number Diff line number Diff line change 1+ {
2+ "version" : " 0.2.0" ,
3+ "configurations" : [
4+ {
5+ "address" : " 127.0.0.1" ,
6+ "localRoot" : " ${workspaceFolder}" ,
7+ "name" : " Attach to Remote Node.js" ,
8+ "port" : 9229 ,
9+ "remoteRoot" : " /var/task/" ,
10+ "request" : " attach" ,
11+ "type" : " node" ,
12+ "preLaunchTask" : " Wait Remote Debugger Server"
13+ },
14+ ]
15+ }
Original file line number Diff line number Diff line change 1+ {
2+ "version" : " 2.0.0" ,
3+ "tasks" : [
4+ {
5+ "label" : " Wait Remote Debugger Server" ,
6+ "type" : " shell" ,
7+ "command" : " while [[ -z $(docker ps | grep :9229) ]]; do sleep 1; done; sleep 1;"
8+ }
9+ ]
10+ }
Original file line number Diff line number Diff line change 1+ export AWS_ACCESS_KEY_ID ?= test
2+ export AWS_SECRET_ACCESS_KEY ?= test
3+ export AWS_DEFAULT_REGION = us-east-1
4+ VENV_DIR ?= .venv
5+
6+ usage : # # Show this help
7+ @fgrep -h " ##" $(MAKEFILE_LIST ) | fgrep -v fgrep | sed -e ' s/\\$$//' | sed -e ' s/##//'
8+
9+ install : # # Install dependencies
10+ @which awslocal || pip install awscli-local
11+ test -e $(VENV_DIR ) || virtualenv $(VENV_DIR )
12+ . $(VENV_DIR ) /bin/activate; pip install debugpy
13+
14+ run : # # Deploy and invoke the Lambda container locally
15+ echo " Deploying Lambda locally" ; \
16+ ./run.sh; \
17+ echo " Done - test successfully finished."
18+
19+ start :
20+ docker-compose up -d
21+
22+ stop :
23+ @echo
24+ localstack stop
25+ ready :
26+ @echo Waiting on the LocalStack container...
27+ @localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1)
28+
29+ logs :
30+ @localstack logs > logs.txt
31+
32+ .PHONY : usage install start run stop ready logs test-ci
Original file line number Diff line number Diff line change 1+ # LocalStack Demo: Lambda Code Mounting and Debugging
2+
3+ Simple demo application to illustrate debugging NodeJS Lambdas locally.
4+
5+ ## Prerequisites
6+
7+ * LocalStack
8+ * Docker
9+ * ` make `
10+ * [ ` awslocal ` ] ( https://github.com/localstack/awscli-local )
11+
12+ ## Installation
13+
14+ To install the dependencies:
15+
16+ ``` sh
17+ make install
18+ ```
19+
20+ ## Starting Up
21+
22+ You can start LocalStack with Docker Compose:
23+
24+ ``` sh
25+ docker-compose up -d
26+ ```
27+
28+ Alternatively, you can use the following ` localstack ` CLI configuration:
29+
30+ ``` sh
31+ LAMBDA_DOCKER_FLAGS=' -e NODE_OPTIONS=--inspect-brk=0.0.0.0:9229 -p 9229:9229' \
32+ LAMBDA_REMOTE_DOCKER=0 \
33+ localstack start -d
34+ ```
35+
36+ ## Running the sample
37+
38+ 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.
39+
40+ The following command deploys the Lambda and finally invoke the Lambda locally:
41+
42+ ``` sh
43+ make run
44+ ```
45+
46+ # License
47+
48+ The code in this sample is available under the Apache 2.0 license.
Original file line number Diff line number Diff line change 1+ version : " 3.8"
2+
3+ services :
4+ localstack :
5+ container_name : " ${LOCALSTACK_DOCKER_NAME-localstack_main}"
6+ image : localstack/localstack:latest
7+ ports :
8+ - " 127.0.0.1:4566:4566" # LocalStack Gateway
9+ - " 127.0.0.1:4510-4559:4510-4559" # external services port range
10+ environment :
11+ - DEBUG=1
12+ - LAMBDA_REMOTE_DOCKER=0
13+ - LAMBDA_DOCKER_FLAGS=-e NODE_OPTIONS=--inspect-brk=0.0.0.0:9229 -p 9229:9229
14+ - LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR-}
15+ - DOCKER_HOST=unix:///var/run/docker.sock
16+ volumes :
17+ - " ${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
18+ - " /var/run/docker.sock:/var/run/docker.sock"
Original file line number Diff line number Diff line change 1+ exports . handler = async ( event ) => {
2+ console . log ( event ) ;
3+ const response = {
4+ statusCode : 200 ,
5+ body : "ok" ,
6+ } ;
7+ return response ;
8+ } ;
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ awslocal lambda create-function \
4+ --function-name localstack-nodejs-lambda-function \
5+ --code S3Bucket=" hot-reload" ,S3Key=" $( pwd) /" \
6+ --handler function.handler \
7+ --runtime nodejs14.x \
8+ --timeout 120 \
9+ --role arn:aws:iam::000000000000:role/lambda-role
10+
11+ awslocal lambda invoke \
12+ --function-name localstack-nodejs-lambda-function test.lambda.log \
13+ --cli-binary-format raw-in-base64-out \
14+ --payload ' {"hello":"world"}'
File renamed without changes.
Original file line number Diff line number Diff line change 1717 ]
1818 }
1919 ]
20- }
20+ }
You can’t perform that action at this time.
0 commit comments