forked from aws/aws-lambda-runtime-interface-emulator
-
Notifications
You must be signed in to change notification settings - Fork 3
Add debugging setup & re-add release optimizations #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
File renamed without changes.
This file contains hidden or 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,4 @@ | ||
aws-lambda-rie | ||
build-delve/dlv | ||
init/var/rapid/init | ||
init/var/rapid/dlv |
File renamed without changes.
This file contains hidden or 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,45 @@ | ||
# Golang EOL overview: https://endoflife.date/go | ||
DOCKER_GOLANG_IMAGE ?= golang:1.18.2 | ||
|
||
# On ARM hosts, use: make ARCH=arm64 build-init | ||
# Check host architecture: uname -m | ||
# x86_64 or arm64 | ||
ARCH ?= x86_64 | ||
|
||
ifeq ($(ARCH), arm64) | ||
GOARCH=arm64 | ||
else | ||
GOARCH=amd64 | ||
endif | ||
|
||
# Limitation: Debugging x86_64 lambdas does not work on ARM machines due to missing ptrace implementation in qemu used by Docker | ||
# The function aborts with "could not launch process: fork/exec /var/rapid/init: function not implemented" | ||
# * Discussion: https://github.com/aws/aws-sam-cli/discussions/4706 | ||
# * Docker for Mac: https://github.com/docker/for-mac/issues/5191#issuecomment-834154431 | ||
|
||
|
||
all: build | ||
|
||
# build & "package" necessary files for debugging | ||
build build-init: build-rapid build-delve/dlv | ||
cp ../bin/aws-lambda-rie-$(ARCH) ./init/var/rapid/init | ||
cp ./build-delve/dlv ./init/var/rapid/dlv | ||
|
||
build-rapid: | ||
cd .. && GC_FLAGS="all=-N -l" make ARCH=$(ARCH) compile-lambda-linux | ||
|
||
build-delve/dlv: | ||
docker run --rm -v $$(pwd)/build-delve/:/app/ $(DOCKER_GOLANG_IMAGE) \ | ||
bash -c "cd /app && export GOARCH=$(GOARCH) && ./build.sh" | ||
|
||
clean clean-init: clean-rapid clean-delve | ||
|
||
clean-rapid: | ||
rm -rf ../bin/aws-lambda-rie-* | ||
rm -rf ./init/var/rapid/init | ||
|
||
clean-delve: | ||
rm -rf ./build-delve/dlv | ||
rm -rf ./init/var/rapid/dlv | ||
|
||
.PHONY: build build-rapid clean clean-rapid clean-delve |
This file contains hidden or 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,36 @@ | ||
# Testing lambda-runtime-init | ||
|
||
## Testing in isolation | ||
Useful if you want more control over the API between the init and LocalStack (e.g. for error responses) | ||
|
||
|
||
## Debugging with LocalStack | ||
|
||
1. Build init via `make build` | ||
* On ARM hosts, use `make ARCH=arm64 build` | ||
|
||
2. Start LocalStack with the following flags: | ||
|
||
``` | ||
LAMBDA_INIT_BIN_PATH=/Users/joe/Projects/LocalStack/lambda-runtime-init/custom-tests/init/var/rapid/init | ||
LAMBDA_INIT_BOOTSTRAP_PATH=/Users/joe/Projects/LocalStack/lambda-runtime-init/custom-tests/init/var/rapid/entrypoint.sh | ||
LAMBDA_INIT_DEBUG=1 | ||
LAMBDA_INIT_DELVE_PATH=/Users/joe/Projects/LocalStack/lambda-runtime-init/custom-tests/init/var/rapid/dlv | ||
LAMBDA_INIT_DELVE_PORT=40000 | ||
LAMBDA_RUNTIME_ENVIRONMENT_TIMEOUT=3600 | ||
TEST_DISABLE_RETRIES_AND_TIMEOUTS=1 | ||
``` | ||
|
||
* `LAMBDA_INIT_DEBUG=1|0` enables or disables RIE copying and debugging. | ||
* `LAMBDA_REMOVE_CONTAINERS=0` keeps exited containers | ||
* Adjust the path to `lambda-runtime-init` accordingly | ||
|
||
3. Start Delve debugger and connect to `localhost:40000` | ||
|
||
|
||
### Advice for function configuration | ||
|
||
Within `create_lambda_function`: | ||
|
||
* Increase the `timeout=3600` | ||
* On ARM hosts, use `Architectures=[Architecture.arm64]` |
File renamed without changes.
This file contains hidden or 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 @@ | ||
#!/usr/bin/env bash | ||
|
||
mkdir -p /tmp/build-delve | ||
cd /tmp/build-delve | ||
git clone https://github.com/go-delve/delve.git | ||
cd delve | ||
make build | ||
mv dlv /app/dlv |
This file contains hidden or 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 @@ | ||
#!/usr/bin/env bash | ||
|
||
LAMBDA_INIT_DELVE_PORT="${LAMBDA_INIT_DELVE_PORT:-40000}" | ||
|
||
# Run init without delve debugger | ||
#exec /var/rapid/init | ||
|
||
exec /var/rapid/dlv --listen=:${LAMBDA_INIT_DELVE_PORT} --headless=true --api-version=2 --accept-multiclient exec /var/rapid/init |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice to optimize the production version 👍