aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Failed to attach debugger

Open smoms opened this issue 7 years ago • 5 comments

Hi, I am following this tutorial: https://docs.aws.amazon.com/en_pv/serverless-application-model/latest/developerguide/serverless-sam-cli-using-debugging-python.html

but i do not know how to step through the code. After all configurations is done I am doing:

  1. run sam local start-api -d 5890
  2. hit the URL 127.0.0.1:3000/hello from browser
  3. start debugger in VSC: I get "failed to attach. Connection refused"

Webpage gets good answer. What am I missing to step through the code?

smoms avatar Oct 01 '19 14:10 smoms

So I think I've solved. Can it be a bug in the doc because in the template.yaml is required to add the sub-path?

CodeUri: hello_world/**build**

smoms avatar Oct 01 '19 15:10 smoms

Did you use a boilerplate application, or your own application? Feel free to redact anything sensitive if using your own code, but could be useful to see the template.yaml that was used.

awood45 avatar Oct 01 '19 16:10 awood45

yes boilerplate.

Here the template where I've made the modification above:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  python-debugging

  Sample SAM Template for python-debugging

# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
  Function:
    Timeout: 3

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      CodeUri: hello_world/build
      Handler: app.lambda_handler
      Runtime: python3.6
      Events:
        HelloWorld:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            Path: /hello
            Method: get

Outputs:
  # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
  # Find out more about other implicit resources you can reference within SAM
  # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
  HelloWorldApi:
    Description: "API Gateway endpoint URL for Prod stage for Hello World function"
    Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
  HelloWorldFunction:
    Description: "Hello World Lambda Function ARN"
    Value: !GetAtt HelloWorldFunction.Arn
  HelloWorldFunctionIamRole:
    Description: "Implicit IAM Role created for Hello World function"
    Value: !GetAtt HelloWorldFunctionRole.Arn

smoms avatar Oct 01 '19 18:10 smoms

Hm, i get the same error, but making the change you suggest just breakes "sam build" command and doesn't fix connection refused debugging error

u2ros avatar Oct 30 '19 21:10 u2ros

Alternatively you can sam build and then do start-api, it will do the codeuri changes for you.

Closing this issue.

sriram-mv avatar Feb 08 '20 00:02 sriram-mv