Summary of my problem:
- I want to be able to run my AWS SAM lambda (Python) locally and use debugger to step into the code that exists in the lambda layer
Project configuration:
- Git repo for lambda function
- Git repo for layer that function will reference
What I'm able to do currently:
- Using guide from here, by using AWS SAM local, I'm able to run debugger just for the lambda and this works fine but I'm unable to step into the method defined in the layer
What happens when I try to step into method from the layer:
- Using vscode debugger, I get redirected somewhere in Python lambda engine (file: bootstrap.py) and I'm unable to navigate to the layer from there
Techs/libs that I use:
- Python3.8 (lambda, layer)
- Debugger: debugpy
- IDE: vscode
- Lambda framework: AWS SAM
Command that I run (before connecting through vscode to debugging session) is:
sam local generate-event apigateway aws-proxy | sam local invoke MyFunction -d 5890 --event inputs/my_event.json
AWS SAM template (function section) looks like this:
MyFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub "${Environment}_${Branch}_my_function"
CodeUri: my_function.zip
Handler: app.handler
Timeout: 180
MemorySize: 512
Layers: # to be substituted with layer arn
- <LAYER_ARN>:<LAYER_VERSION>
If I'm correct, when I run command from above, following happens:
- Docker container gets created from SAM Docker image
- Docker container contains layer downloaded from AWS
- SAM unzips content from my_function.zip and mounts content into the docker container
- Docker container has 5890 debugging port exposed so that we are able to connect from the vscode (for example) to the debugging session
My theory is that, as long as the layer is downloaded from the AWS, I will not be able to see that code in debugging session in vscode ? So, one thing that I'm thinking, but not sure if it is possible is to, instead of referencing LAYER_ARN, I reference specific folder on my local machine where layer code exists.
Question 1: If my theory is correct, is it possible to do this and how?
Question 2: If my theory is not correct, are there any other ways to achieve debugging of the layer code in this setup?
question from:
https://stackoverflow.com/questions/66049753/how-to-locally-debug-aws-sam-lambda-function-python-which-references-layer-tha 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…