Skip to content

Commit 5a4c741

Browse files
Add debugging setup & re-add release optimizations (#12)
Co-authored-by: Joel Scheuner <[email protected]>
1 parent db1cead commit 5a4c741

File tree

14 files changed

+104
-27
lines changed

14 files changed

+104
-27
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
go-version: '~1.18.2'
2121

2222
- name: Build
23+
env:
24+
RELEASE_BUILD_LINKER_FLAGS: "-s -w"
2325
run: make compile-lambda-linux-all
2426

2527
- uses: actions/upload-artifact@v3

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# RELEASE_BUILD_LINKER_FLAGS disables DWARF and symbol table generation to reduce binary size
66
#RELEASE_BUILD_LINKER_FLAGS=-s -w
77

8-
98
BINARY_NAME=aws-lambda-rie
109
ARCH=x86_64
1110
GO_ARCH_x86_64 := amd64
@@ -25,7 +24,7 @@ compile-with-docker:
2524
docker run --rm --env GOPROXY=direct -v $(shell pwd):/LambdaRuntimeLocal -w /LambdaRuntimeLocal golang:1.18 make ARCH=${ARCH} compile-lambda-linux
2625

2726
compile-lambda-linux:
28-
CGO_ENABLED=0 GOOS=linux GOARCH=${GO_ARCH_${ARCH}} go build -ldflags "${RELEASE_BUILD_LINKER_FLAGS}" -gcflags="all=-N -l" -o ${DESTINATION_${ARCH}} ./cmd/localstack
27+
CGO_ENABLED=0 GOOS=linux GOARCH=${GO_ARCH_${ARCH}} go build -ldflags "${RELEASE_BUILD_LINKER_FLAGS}" -gcflags="${GC_FLAGS}" -o ${DESTINATION_${ARCH}} ./cmd/localstack
2928

3029
tests:
3130
go test ./...

custom-tests/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

custom-tests/Makefile

Lines changed: 0 additions & 16 deletions
This file was deleted.

custom-tests/README.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

custom-tests/dlv

-15.9 MB
Binary file not shown.
File renamed without changes.

debugging/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
aws-lambda-rie
2+
build-delve/dlv
3+
init/var/rapid/init
4+
init/var/rapid/dlv
File renamed without changes.

debugging/Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Golang EOL overview: https://endoflife.date/go
2+
DOCKER_GOLANG_IMAGE ?= golang:1.18.2
3+
4+
# On ARM hosts, use: make ARCH=arm64 build-init
5+
# Check host architecture: uname -m
6+
# x86_64 or arm64
7+
ARCH ?= x86_64
8+
9+
ifeq ($(ARCH), arm64)
10+
GOARCH=arm64
11+
else
12+
GOARCH=amd64
13+
endif
14+
15+
# Limitation: Debugging x86_64 lambdas does not work on ARM machines due to missing ptrace implementation in qemu used by Docker
16+
# The function aborts with "could not launch process: fork/exec /var/rapid/init: function not implemented"
17+
# * Discussion: https://github.com/aws/aws-sam-cli/discussions/4706
18+
# * Docker for Mac: https://github.com/docker/for-mac/issues/5191#issuecomment-834154431
19+
20+
21+
all: build
22+
23+
# build & "package" necessary files for debugging
24+
build build-init: build-rapid build-delve/dlv
25+
cp ../bin/aws-lambda-rie-$(ARCH) ./init/var/rapid/init
26+
cp ./build-delve/dlv ./init/var/rapid/dlv
27+
28+
build-rapid:
29+
cd .. && GC_FLAGS="all=-N -l" make ARCH=$(ARCH) compile-lambda-linux
30+
31+
build-delve/dlv:
32+
docker run --rm -v $$(pwd)/build-delve/:/app/ $(DOCKER_GOLANG_IMAGE) \
33+
bash -c "cd /app && export GOARCH=$(GOARCH) && ./build.sh"
34+
35+
clean clean-init: clean-rapid clean-delve
36+
37+
clean-rapid:
38+
rm -rf ../bin/aws-lambda-rie-*
39+
rm -rf ./init/var/rapid/init
40+
41+
clean-delve:
42+
rm -rf ./build-delve/dlv
43+
rm -rf ./init/var/rapid/dlv
44+
45+
.PHONY: build build-rapid clean clean-rapid clean-delve

debugging/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Testing lambda-runtime-init
2+
3+
## Testing in isolation
4+
Useful if you want more control over the API between the init and LocalStack (e.g. for error responses)
5+
6+
7+
## Debugging with LocalStack
8+
9+
1. Build init via `make build`
10+
* On ARM hosts, use `make ARCH=arm64 build`
11+
12+
2. Start LocalStack with the following flags:
13+
14+
```
15+
LAMBDA_INIT_BIN_PATH=/Users/joe/Projects/LocalStack/lambda-runtime-init/custom-tests/init/var/rapid/init
16+
LAMBDA_INIT_BOOTSTRAP_PATH=/Users/joe/Projects/LocalStack/lambda-runtime-init/custom-tests/init/var/rapid/entrypoint.sh
17+
LAMBDA_INIT_DEBUG=1
18+
LAMBDA_INIT_DELVE_PATH=/Users/joe/Projects/LocalStack/lambda-runtime-init/custom-tests/init/var/rapid/dlv
19+
LAMBDA_INIT_DELVE_PORT=40000
20+
LAMBDA_RUNTIME_ENVIRONMENT_TIMEOUT=3600
21+
TEST_DISABLE_RETRIES_AND_TIMEOUTS=1
22+
```
23+
24+
* `LAMBDA_INIT_DEBUG=1|0` enables or disables RIE copying and debugging.
25+
* `LAMBDA_REMOVE_CONTAINERS=0` keeps exited containers
26+
* Adjust the path to `lambda-runtime-init` accordingly
27+
28+
3. Start Delve debugger and connect to `localhost:40000`
29+
30+
31+
### Advice for function configuration
32+
33+
Within `create_lambda_function`:
34+
35+
* Increase the `timeout=3600`
36+
* On ARM hosts, use `Architectures=[Architecture.arm64]`
File renamed without changes.

debugging/build-delve/build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
mkdir -p /tmp/build-delve
4+
cd /tmp/build-delve
5+
git clone https://github.com/go-delve/delve.git
6+
cd delve
7+
make build
8+
mv dlv /app/dlv
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
LAMBDA_INIT_DELVE_PORT="${LAMBDA_INIT_DELVE_PORT:-40000}"
4+
5+
# Run init without delve debugger
6+
#exec /var/rapid/init
7+
8+
exec /var/rapid/dlv --listen=:${LAMBDA_INIT_DELVE_PORT} --headless=true --api-version=2 --accept-multiclient exec /var/rapid/init

0 commit comments

Comments
 (0)