Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
480 views
in Technique[技术] by (71.8m points)

visual studio code - How to locally debug AWS SAM Lambda function (Python) which references layer that exists on different git repo/project

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:

  1. Docker container gets created from SAM Docker image
  2. Docker container contains layer downloaded from AWS
  3. SAM unzips content from my_function.zip and mounts content into the docker container
  4. 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...