Develop and debug AWS SAM functions locally from VS Code Dev Containers
- Docker (tested on macOS, Linux)
- VS Code with Remote - Containers extension installed
Also works in GitHub Codespaces.
- Clone the repository
git clone https://github.com/ilyasotkov/aws-sam-local-python-devcontainer.git
- Open the cloned folder in VS Code. You'll be prompted to reopen in container, agree by pressing "Reopen in container".
- Wait for container image to build and container to launch and VS Code extensions to download.
- Go to
./src/main.py
. Uncomment all commented out lines (this is so that the Lambda function will wait for VS Code debugger to attach). Set a breakpoint in thelambda_handler
function at theprint(json.dumps(event, indent=2))
line. - Go to the debug tab in VS Code, and press on "Start Debugging". Debugger should automatically attach and hit the breakpoint that you've set.
Happens because you Start Debugging
while the ms-python.debugpy
VSCode extension is still installing. Solution: wait for the extension to install, you can check the installation status in VSCode's Extensions view.
This repo has only been tested on x86_64 architecture. If you get it working on arm64, feel free to submit a PR!