aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.5k stars 1.17k forks source link

Debug locally #4522

Open marciogoulart opened 1 year ago

marciogoulart commented 1 year ago

Hi,

I would like support to debug a lambda built in CDK locally in VSCODE.

When I run the lambda via SAM LOCAL INVOKE it works perfectly, but when I add a breakpoint and run it in debug mode, some problems arise.

I performed some tests, the main problem is not finding the debugpy module, but it is attached.

Can you help-me?

Thanks,

marciogoulart commented 1 year ago

lauch.json:

{ "configurations": [ { "type": "aws-sam", "request": "direct-invoke", "name": "CodeverifyLocationLambda", "invokeTarget": { "target": "code", "projectRoot": "VerifyLocationLambda", "lambdaHandler": "verifyLocationLambda.lambda_handler" }, "sam": { "localArguments": [ "--template", "${workspaceFolder}/NaasVerifyLocationRepository/infra/cdk.out/VerifyLocationFunctionStack.template.json", "--debug" ] }, "lambda": { "runtime": "python3.8", "memoryMb": 128, "timeoutSec": 30, "payload": { "path": "${workspaceFolder}/NaasVerifyLocationRepository/infra/test.json" }, "environmentVariables": { "AWS_PROFILE": "outposts-stage" }, }, } ] }

LOG:

2022-12-16 10:02:02 [INFO]: Preparing to debug locally: Lambda "verifyLocationLambda.lambda_handler" 2022-12-16 10:02:02 [INFO]: Building SAM application... 2022-12-16 10:02:02 [INFO]: Command: (not started) [C:\Program Files\Amazon\AWSSAMCLI\bin\sam.cmd build --debug --build-dir C:\Users\GOULART\AppData\Local\Temp\aws-toolkit-vscode\vsctkmTivSZ\output --template C:/Users/GOULART/AppData/Local/Temp/aws-toolkit-vscode/vsctkmTivSZ/appvsctktemplate.yaml --base-dir C:/Users/GOULART/Documents/UnidadeD/workspace_naas/VerifyLocationLambda --manifest C:\Users\GOULART\AppData\Local\Temp\aws-toolkit-vscode\vsctkmTivSZ\debug-requirements.txt] 2022-12-16 10:02:03 [INFO]: 2022-12-16 10:02:03,077 | Using SAM Template at C:\Users\GOULART\AppData\Local\Temp\aws-toolkit-vscode\vsctkmTivSZ\appvsctktemplate.yaml

2022-12-16 10:02:03 [INFO]: 2022-12-16 10:02:03,077 | Config file location: C:\Users\GOULART\AppData\Local\Temp\aws-toolkit-vscode\vsctkmTivSZ\samconfig.toml 2022-12-16 10:02:03,078 | Config file 'C:\Users\GOULART\AppData\Local\Temp\aws-toolkit-vscode\vsctkmTivSZ\samconfig.toml' does not exist

2022-12-16 10:02:03 [INFO]: 2022-12-16 10:02:03,210 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics

2022-12-16 10:02:03 [INFO]: 2022-12-16 10:02:03,210 | Using config file: samconfig.toml, config environment: default 2022-12-16 10:02:03,211 | Expand command line arguments to: 2022-12-16 10:02:03,211 | --template_file=C:\Users\GOULART\AppData\Local\Temp\aws-toolkit-vscode\vsctkmTivSZ\appvsctktemplate.yaml --build_dir=C:\Users\GOULART\AppData\Local\Temp\aws-toolkit-vscode\vsctkmTivSZ\output --base_dir=C:/Users/GOULART/Documents/UnidadeD/workspace_naas/VerifyLocationLambda --manifest=C:\Users\GOULART\AppData\Local\Temp\aws-toolkit-vscode\vsctkmTivSZ\debug-requirements.txt --cache_dir=.aws-sam\cache

2022-12-16 10:02:04 [INFO]: 2022-12-16 10:02:04,795 | 'build' command is called

2022-12-16 10:02:04 [INFO]: 2022-12-16 10:02:04,802 | No Parameters detected in the template

2022-12-16 10:02:04 [INFO]: 2022-12-16 10:02:04,844 | There is no customer defined id or cdk path defined for resource VerifyLocationLambda, so we will use the resource logical id as the resource id

2022-12-16 10:02:04 [INFO]: 2022-12-16 10:02:04,844 | 0 stacks found in the template 2022-12-16 10:02:04,845 | No Parameters detected in the template

2022-12-16 10:02:04 [INFO]: 2022-12-16 10:02:04,885 | There is no customer defined id or cdk path defined for resource VerifyLocationLambda, so we will use the resource logical id as the resource id

2022-12-16 10:02:04 [INFO]: 2022-12-16 10:02:04,887 | 1 resources found in the stack 2022-12-16 10:02:04,888 | Found Serverless function with name='VerifyLocationLambda' and CodeUri='C:/Users/GOULART/Documents/UnidadeD/workspace_naas/VerifyLocationLambda'

2022-12-16 10:02:04 [INFO]: 2022-12-16 10:02:04,896 | 1 resources found in the stack

2022-12-16 10:02:04 [INFO]: 2022-12-16 10:02:04,896 | Found Serverless function with name='VerifyLocationLambda' and CodeUri='C:/Users/GOULART/Documents/UnidadeD/workspace_naas/VerifyLocationLambda'

2022-12-16 10:02:04 [INFO]: 2022-12-16 10:02:04,897 | Instantiating build definitions

2022-12-16 10:02:04 [INFO]: 2022-12-16 10:02:04,908 | No previous build graph found, generating new one

2022-12-16 10:02:04 [INFO]: 2022-12-16 10:02:04,911 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(python3.8, C:/Users/GOULART/Documents/UnidadeD/workspace_naas/VerifyLocationLambda, Zip, , 4e01c7c0-54cf-4a31-9021-60f7a8780728, {}, {}, x86_64, []), Function: Function(function_id='VerifyLocationLambda', name='VerifyLocationLambda', functionname='VerifyLocationLambda', runtime='python3.8', memory=128, timeout=30, handler='verifyLocationLambda.lambda_handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='C:/Users/GOULART/Documents/UnidadeD/workspace_naas/VerifyLocationLambda', environment={'Variables': {'AWS_PROFILE': 'outposts-stage'}}, rolearn=None, layers=[], events=None, metadata={'SamResourceId': 'VerifyLocationLambda'}, inlinecode=None, codesign_config_arn=None, architectures=None, function_url_config=None, stack_path=''))

2022-12-16 10:02:04 [INFO]: 2022-12-16 10:02:04,925 | Building codeuri: C:/Users/GOULART/Documents/UnidadeD/workspace_naas/VerifyLocationLambda runtime: python3.8 metadata: {} architecture: x86_64 functions: VerifyLocationLambda

2022-12-16 10:02:04 [INFO]: 2022-12-16 10:02:04,925 | Building to following folder C:\Users\GOULART\AppData\Local\Temp\aws-toolkit-vscode\vsctkmTivSZ\output\VerifyLocationLambda

2022-12-16 10:02:04 [INFO]: 2022-12-16 10:02:04,928 | Loading workflow module 'aws_lambda_builders.workflows'

2022-12-16 10:02:05 [INFO]: 2022-12-16 10:02:05,894 | Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)'

2022-12-16 10:02:06 [INFO]: 2022-12-16 10:02:06,061 | Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'

2022-12-16 10:02:06 [INFO]: 2022-12-16 10:02:06,304 | Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)'

2022-12-16 10:02:06 [INFO]: 2022-12-16 10:02:06,411 | Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)'

2022-12-16 10:02:06 [INFO]: 2022-12-16 10:02:06,610 | Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)'

2022-12-16 10:02:06 [INFO]: 2022-12-16 10:02:06,687 | Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)'

2022-12-16 10:02:06 [INFO]: 2022-12-16 10:02:06,843 | Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'

2022-12-16 10:02:06 [INFO]: 2022-12-16 10:02:06,924 | Registering workflow 'CustomMakeBuilder' with capability 'Capability(language='provided', dependency_manager=None, application_framework=None)'

2022-12-16 10:02:07 [INFO]: 2022-12-16 10:02:07,018 | Registering workflow 'NodejsNpmEsbuildBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm-esbuild', application_framework=None)'

2022-12-16 10:02:07 [INFO]: 2022-12-16 10:02:07,018 | Found workflow 'PythonPipBuilder' to support capabilities 'Capability(language='python', dependency_manager='pip', application_framework=None)'

2022-12-16 10:02:07 [INFO]: 2022-12-16 10:02:07,241 | Running workflow 'PythonPipBuilder' 2022-12-16 10:02:07,241 | Running PythonPipBuilder:ResolveDependencies

2022-12-16 10:02:07 [INFO]: 2022-12-16 10:02:07,373 | calling pip download -r C:\Users\GOULART\AppData\Local\Temp\aws-toolkit-vscode\vsctkmTivSZ\debug-requirements.txt --dest C:\Users\GOULART\AppData\Local\Temp\tmpbj0iwcze --exists-action i

2022-12-16 10:02:12 [INFO]: 2022-12-16 10:02:12,156 | Full dependency closure: {debugpy==1.6.4(wheel)}

2022-12-16 10:02:12 [INFO]: 2022-12-16 10:02:12,156 | initial compatible: set() 2022-12-16 10:02:12,157 | initial incompatible: {debugpy==1.6.4(wheel)} 2022-12-16 10:02:12,157 | Downloading missing wheels: {debugpy==1.6.4(wheel)} 2022-12-16 10:02:12,157 | calling pip download --only-binary=:all: --no-deps --platform manylinux2014_x86_64 --implementation cp --abi cp38 --dest C:\Users\GOULART\AppData\Local\Temp\tmpbj0iwcze debugpy==1.6.4

2022-12-16 10:02:14 [INFO]: 2022-12-16 10:02:14,520 | compatible wheels after second download pass: {debugpy==1.6.4(wheel)} 2022-12-16 10:02:14,520 | Build missing wheels from sdists (C compiling True): set()

2022-12-16 10:02:14 [INFO]: 2022-12-16 10:02:14,521 | compatible after building wheels (no C compiling): {debugpy==1.6.4(wheel)} 2022-12-16 10:02:14,521 | Build missing wheels from sdists (C compiling False): set() 2022-12-16 10:02:14,521 | compatible after building wheels (C compiling): {debugpy==1.6.4(wheel)} 2022-12-16 10:02:14,521 | Final compatible: {debugpy==1.6.4(wheel)} 2022-12-16 10:02:14,521 | Final incompatible: {debugpy==1.6.4(wheel)} 2022-12-16 10:02:14,521 | Final missing wheels: set()

2022-12-16 10:02:15 [INFO]: 2022-12-16 10:02:15,386 | PythonPipBuilder:ResolveDependencies succeeded 2022-12-16 10:02:15,386 | Running PythonPipBuilder:CopySource

2022-12-16 10:02:15 [INFO]: 2022-12-16 10:02:15,386 | Skipping copy operation since source C:\Users\GOULART\Documents\UnidadeD\workspace_naas\VerifyLocationLambda does not exist 2022-12-16 10:02:15,386 | PythonPipBuilder:CopySource succeeded

2022-12-16 10:02:15 [INFO]: 2022-12-16 10:02:15,390 | There is no customer defined id or cdk path defined for resource VerifyLocationLambda, so we will use the resource logical id as the resource id

2022-12-16 10:02:15 [INFO]: 2022-12-16 10:02:15,392 | 1 resources found in the stack 2022-12-16 10:02:15,392 | Found Serverless function with name='VerifyLocationLambda' and CodeUri='C:/Users/GOULART/Documents/UnidadeD/workspace_naas/VerifyLocationLambda'

2022-12-16 10:02:15 [INFO]: Build Succeeded

Built Artifacts : output Built Template : output\template.yaml

Commands you can use next

[*] Validate SAM template: sam validate

[*] Invoke Function: sam local invoke -t output\template.yaml

[*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch

[*] Deploy: sam deploy --guided --template-file output\template.yaml

2022-12-16 10:02:15 [INFO]: 2022-12-16 10:02:15,890 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics

2022-12-16 10:02:15 [INFO]: 2022-12-16 10:02:15,890 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '6d0625dc-da85-4a55-a5bf-9e423c76f69c', 'installationId': 'da828c30-2f56-44e1-8b43-559172e20903', 'sessionId': '89176a63-999f-4f79-868b-8ee1b8a7795e', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.8', 'samcliVersion': '1.66.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': 'fb86f7ad7c099cf3e9c88c94b41dbe99a75cd936ee4f713011d37000923e6643', 'projectName': 'bd400ae6ffd2a68772e15a4c6ef45fbfc20d130c67355a246ae4ca875dfe81a5', 'initialCommit': 'd9c5eb19524e63440b8791b9b46aa870a0889cc23fe53062908768780ddbb26a'}, 'duration': 12677, 'exitReason': 'success', 'exitCode': 0}}]} 2022-12-16 10:02:15,890 | Unable to find Click Context for getting session_id.

2022-12-16 10:02:15 [INFO]: 2022-12-16 10:02:15,896 | Sending Telemetry: {'metrics': [{'events': {'requestId': 'b88ffbb7-c14a-4e13-8977-60cf6e43346c', 'installationId': 'da828c30-2f56-44e1-8b43-559172e20903', 'sessionId': '89176a63-999f-4f79-868b-8ee1b8a7795e', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.8', 'samcliVersion': '1.66.0', 'metricSpecificAttributes': {'events': [{'event_name': 'BuildWorkflowUsed', 'event_value': 'python-pip', 'thread_id': 13480, 'time_stamp': '2022-12-16 13:02:04.925'}, {'event_name': 'BuildFunctionRuntime', 'event_value': 'python3.8', 'thread_id': 13480, 'time_stamp': '2022-12-16 13:02:15.397'}]}}}]}

2022-12-16 10:02:16 [INFO]: 2022-12-16 10:02:16,684 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)

2022-12-16 10:02:16 [INFO]: 2022-12-16 10:02:16,718 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)

2022-12-16 10:02:16 [INFO]: Build complete. 2022-12-16 10:02:16 [INFO]: Starting SAM application locally 2022-12-16 10:02:16 [INFO]: AWS.running.command 2022-12-16 10:02:18,574 | Using SAM Template at C:\Users\GOULART\Documents\UnidadeD\workspace_naas\NaasVerifyLocationRepository\infra\cdk.out\VerifyLocationFunctionStack.template.json 2022-12-16 10:02:18,574 | Config file location: C:\Users\GOULART\Documents\UnidadeD\workspace_naas\NaasVerifyLocationRepository\infra\cdk.out\samconfig.toml 2022-12-16 10:02:18,575 | Config file 'C:\Users\GOULART\Documents\UnidadeD\workspace_naas\NaasVerifyLocationRepository\infra\cdk.out\samconfig.toml' does not exist 2022-12-16 10:02:18,607 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics 2022-12-16 10:02:18,607 | Using config file: samconfig.toml, config environment: default 2022-12-16 10:02:18,607 | Expand command line arguments to: 2022-12-16 10:02:18,607 | --template_file=C:\Users\GOULART\Documents\UnidadeD\workspace_naas\NaasVerifyLocationRepository\infra\cdk.out\VerifyLocationFunctionStack.template.json --event=C:\Users\GOULART\AppData\Local\Temp\aws-toolkit-vscode\vsctkmTivSZ\event.json --env_vars=C:\Users\GOULART\AppData\Local\Temp\aws-toolkit-vscode\vsctkmTivSZ\env-vars.json --debug_port=(5858,) --debugger_path=c:\Users\GOULART.vscode\extensions\amazonwebservices.aws-toolkit-vscode-1.59.0\resources\debugger --debug_args=/tmp/lambci_debug_files/py_debug_wrapper.py --listen 0.0.0.0:5858 --wait-for-client --log-to-stderr --debug --function_logical_id=VerifyLocationLambda --no_event --layer_cache_basedir=C:\Users\GOULART\AppData\Roaming\AWS SAM\layers-pkg --container_host=localhost --container_host_interface=127.0.0.1 2022-12-16 10:02:18,608 | local invoke command is called 2022-12-16 10:02:18,982 | Collected default values for parameters: {} 2022-12-16 10:02:19,077 | CDK Path for resource eventSourceParamCF505C7B is ['VerifyLocationFunctionStack', 'eventSourceParam', 'Resource'] 2022-12-16 10:02:19,077 | CDK Path for resource VerifyLocationLambdaServiceRole4AF28A92 is ['VerifyLocationFunctionStack', 'VerifyLocationLambda', 'ServiceRole', 'Resource'] 2022-12-16 10:02:19,077 | CDK Path for resource VerifyLocationLambdaServiceRoleDefaultPolicy4D58E88F is ['VerifyLocationFunctionStack', 'VerifyLocationLambda', 'ServiceRole', 'DefaultPolicy', 'Resource'] 2022-12-16 10:02:19,077 | CDK Path for resource VerifyLocationLambdaD1B39A9A is ['VerifyLocationFunctionStack', 'VerifyLocationLambda', 'Resource'] 2022-12-16 10:02:19,077 | CDK Path for resource VerifyLocationLambdaLogRetention51AEF3F2 is ['VerifyLocationFunctionStack', 'VerifyLocationLambda', 'LogRetention', 'Resource'] 2022-12-16 10:02:19,078 | CDK Path for resource VerifyLocationLambdaEventInvokeConfig739D575C is ['VerifyLocationFunctionStack', 'VerifyLocationLambda', 'EventInvokeConfig', 'Resource'] 2022-12-16 10:02:19,078 | CDK Path for resource LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRole9741ECFB is ['VerifyLocationFunctionStack', 'LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8a', 'ServiceRole', 'Resource'] 2022-12-16 10:02:19,078 | CDK Path for resource LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRoleDefaultPolicyADDA7DEB is ['VerifyLocationFunctionStack', 'LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8a', 'ServiceRole', 'DefaultPolicy', 'Resource'] 2022-12-16 10:02:19,078 | CDK Path for resource LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aFD4BFC8A is ['VerifyLocationFunctionStack', 'LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8a', 'Resource'] 2022-12-16 10:02:19,078 | CDK Path for resource CDKMetadata is ['VerifyLocationFunctionStack', 'CDKMetadata', 'Default'] 2022-12-16 10:02:19,081 | 0 stacks found in the template 2022-12-16 10:02:19,081 | Collected default values for parameters: {} 2022-12-16 10:02:19,142 | CDK Path for resource eventSourceParamCF505C7B is ['VerifyLocationFunctionStack', 'eventSourceParam', 'Resource'] 2022-12-16 10:02:19,145 | CDK Path for resource VerifyLocationLambdaServiceRole4AF28A92 is ['VerifyLocationFunctionStack', 'VerifyLocationLambda', 'ServiceRole', 'Resource'] 2022-12-16 10:02:19,146 | CDK Path for resource VerifyLocationLambdaServiceRoleDefaultPolicy4D58E88F is ['VerifyLocationFunctionStack', 'VerifyLocationLambda', 'ServiceRole', 'DefaultPolicy', 'Resource'] 2022-12-16 10:02:19,146 | CDK Path for resource VerifyLocationLambdaD1B39A9A is ['VerifyLocationFunctionStack', 'VerifyLocationLambda', 'Resource'] 2022-12-16 10:02:19,151 | CDK Path for resource VerifyLocationLambdaLogRetention51AEF3F2 is ['VerifyLocationFunctionStack', 'VerifyLocationLambda', 'LogRetention', 'Resource'] 2022-12-16 10:02:19,151 | CDK Path for resource VerifyLocationLambdaEventInvokeConfig739D575C is ['VerifyLocationFunctionStack', 'VerifyLocationLambda', 'EventInvokeConfig', 'Resource'] 2022-12-16 10:02:19,152 | CDK Path for resource LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRole9741ECFB is ['VerifyLocationFunctionStack', 'LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8a', 'ServiceRole', 'Resource'] 2022-12-16 10:02:19,152 | CDK Path for resource LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aServiceRoleDefaultPolicyADDA7DEB is ['VerifyLocationFunctionStack', 'LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8a', 'ServiceRole', 'DefaultPolicy', 'Resource'] 2022-12-16 10:02:19,158 | CDK Path for resource LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aFD4BFC8A is ['VerifyLocationFunctionStack', 'LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8a', 'Resource'] 2022-12-16 10:02:19,158 | CDK Path for resource CDKMetadata is ['VerifyLocationFunctionStack', 'CDKMetadata', 'Default'] 2022-12-16 10:02:19,161 | 10 resources found in the stack 2022-12-16 10:02:19,165 | Found Lambda function with name='VerifyLocationLambdaD1B39A9A' and CodeUri='asset.c2e5d44a9581aa5eaddd574a45d766e3369b90adda3b4a0d50193346aad4007b' 2022-12-16 10:02:19,165 | --base-dir is not presented, adjusting uri asset.c2e5d44a9581aa5eaddd574a45d766e3369b90adda3b4a0d50193346aad4007b relative to C:\Users\GOULART\Documents\UnidadeD\workspace_naas\NaasVerifyLocationRepository\infra\cdk.out\VerifyLocationFunctionStack.template.json 2022-12-16 10:02:19,169 | Found Lambda function with name='LogRetentionaae0aa3c5b4d4f87b02d85b201efdd8aFD4BFC8A' and CodeUri='asset.c8dfcc3db7a767ebc6f9417372a8fee940927c659f793315834a6784dab3d686' 2022-12-16 10:02:19,169 | --base-dir is not presented, adjusting uri asset.c8dfcc3db7a767ebc6f9417372a8fee940927c659f793315834a6784dab3d686 relative to C:\Users\GOULART\Documents\UnidadeD\workspace_naas\NaasVerifyLocationRepository\infra\cdk.out\VerifyLocationFunctionStack.template.json 2022-12-16 10:02:19,252 | Found one Lambda function with name 'VerifyLocationLambda' 2022-12-16 10:02:19,253 | Invoking verifyLocationLambda.lambda_handler (python3.8) 2022-12-16 10:02:19,253 | Environment variables data found for specific function in standard format 2022-12-16 10:02:19,253 | Loading AWS credentials from session with profile 'None' 2022-12-16 10:02:19,997 | Resolving code path. Cwd=C:\Users\GOULART\Documents\UnidadeD\workspace_naas\NaasVerifyLocationRepository\infra\cdk.out, CodeUri=C:\Users\GOULART\Documents\UnidadeD\workspace_naas\NaasVerifyLocationRepository\infra\cdk.out\asset.c2e5d44a9581aa5eaddd574a45d766e3369b90adda3b4a0d50193346aad4007b 2022-12-16 10:02:19,997 | Resolved absolute path to code is C:\Users\GOULART\Documents\UnidadeD\workspace_naas\NaasVerifyLocationRepository\infra\cdk.out\asset.c2e5d44a9581aa5eaddd574a45d766e3369b90adda3b4a0d50193346aad4007b 2022-12-16 10:02:19,998 | Code C:\Users\GOULART\Documents\UnidadeD\workspace_naas\NaasVerifyLocationRepository\infra\cdk.out\asset.c2e5d44a9581aa5eaddd574a45d766e3369b90adda3b4a0d50193346aad4007b is not a zip/jar file 2022-12-16 10:02:19,999 | arn:aws:lambda:sa-east-1:122379730124:layer:NetApiLayer:2 is already cached. Skipping download 2022-12-16 10:02:20,000 | arn:aws:lambda:sa-east-1:122379730124:layer:PowerToolsLambdaLayer:2 is already cached. Skipping download 2022-12-16 10:02:20,044 | Skip pulling image and use local one: samcli/lambda:python3.8-x86_64-c92f23e4e69643360eef042b3.

2022-12-16 10:02:20,044 | Mounting C:\Users\GOULART\Documents\UnidadeD\workspace_naas\NaasVerifyLocationRepository\infra\cdk.out\asset.c2e5d44a9581aa5eaddd574a45d766e3369b90adda3b4a0d50193346aad4007b as /var/task:ro,delegated inside runtime container 2022-12-16 10:02:24,309 | Setting up SIGTERM interrupt handler START RequestId: 2a359d95-b1d3-4e39-b373-25666e15205f Version: $LATEST Prepending Lambda task root to path: /var/task Starting debugger... 2022-12-16 10:02:25 [ERROR]: Traceback (most recent call last): File "/tmp/lambci_debug_files/py_debug_wrapper.py", line 46, in runpy.run_module('debugpy', run_name='main') File "/var/lang/lib/python3.8/runpy.py", line 203, in run_module mod_name, mod_spec, code = _get_module_details(mod_name) File "/var/lang/lib/python3.8/runpy.py", line 138, in _get_module_details raise error("No module named { raw: true }" % mod_name) ImportError: No module named debugpy

16 Dec 2022 13:02:25,994 [ERROR] (rapid) Init failed InvokeID= error=Runtime exited with error: exit status 1 Prepending Lambda task root to path: /var/task Starting debugger... 2022-12-16 10:02:26 [ERROR]: Traceback (most recent call last): File "/tmp/lambci_debug_files/py_debug_wrapper.py", line 46, in runpy.run_module('debugpy', run_name='main') File "/var/lang/lib/python3.8/runpy.py", line 203, in run_module mod_name, mod_spec, code = _get_module_details(mod_name) File "/var/lang/lib/python3.8/runpy.py", line 138, in _get_module_details raise error("No module named { raw: true }" % mod_name) ImportError: No module named debugpy

END RequestId: 63998952-6b36-4b3e-8552-6dea56329311 REPORT RequestId: 63998952-6b36-4b3e-8552-6dea56329311 Init Duration: 0.16 ms Duration: 254.86 ms Billed Duration: 255 ms Memory Size: 128 MB Max Memory Used: 128 MB 2022-12-16 10:02:26,356 | Failed to get the logs from the container Traceback (most recent call last): File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\samcli\local\docker\container.py", line 402, in _write_container_output for stdout_data, stderr_data in output_itr: File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\types\daemon.py", line 32, in next return next(self._stream) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\api\client.py", line 406, in gen = (demux_adaptor(frame) for frame in gen) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\socket.py", line 94, in frames_iter_no_tty (stream, n) = next_frame_header(socket) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\socket.py", line 66, in next_frame_header data = read_exactly(socket, 8) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\socket.py", line 51, in read_exactly next_data = read(socket, n - len(data)) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\utils\socket.py", line 35, in read return socket.recv(n) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\transport\npipesocket.py", line 23, in wrapped return f(self, args, **kwargs) File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\docker\transport\npipesocket.py", line 117, in recv err, data = win32file.ReadFile(self._handle, bufsize) pywintypes.error: (109, 'ReadFile', 'O pipe foi finalizado.') 2022-12-16 10:02:27,786 | Cleaning all decompressed code dirs 2022-12-16 10:02:28,239 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics 2022-12-16 10:02:28,239 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': 'bacecddb-1936-4bfa-bc34-68e056d9a54f', 'installationId': 'da828c30-2f56-44e1-8b43-559172e20903', 'sessionId': '82f53ba0-9aa0-482f-9086-dc23957b14fb', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.8', 'samcliVersion': '1.66.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam local invoke', 'metricSpecificAttributes': {'projectType': 'CDK', 'gitOrigin': 'fb86f7ad7c099cf3e9c88c94b41dbe99a75cd936ee4f713011d37000923e6643', 'projectName': 'bd400ae6ffd2a68772e15a4c6ef45fbfc20d130c67355a246ae4ca875dfe81a5', 'initialCommit': 'd9c5eb19524e63440b8791b9b46aa870a0889cc23fe53062908768780ddbb26a'}, 'duration': 9632, 'exitReason': 'success', 'exitCode': 0}}]} 2022-12-16 10:02:28,240 | Unable to find Click Context for getting session_id. 2022-12-16 10:02:28,243 | Sending Telemetry: {'metrics': [{'events': {'requestId': '9d9ad158-59eb-458f-bdf3-6afe2e06b047', 'installationId': 'da828c30-2f56-44e1-8b43-559172e20903', 'sessionId': '82f53ba0-9aa0-482f-9086-dc23957b14fb', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.8', 'samcliVersion': '1.66.0', 'metricSpecificAttributes': {'events': [{'event_name': 'UsedFeature', 'event_value': 'CDK', 'thread_id': 1284, 'time_stamp': '2022-12-16 13:02:27.787'}]}}}]} 2022-12-16 10:02:29,085 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1) 2022-12-16 10:02:29,085 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1) 2022-12-16 10:02:29,086 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics 2022-12-16 10:02:29,086 | Sending Telemetry: {'metrics': [{'runtimeMetric': {'requestId': 'e32c42b5-ad74-45be-8334-316f8691c992', 'installationId': 'da828c30-2f56-44e1-8b43-559172e20903', 'sessionId': '82f53ba0-9aa0-482f-9086-dc23957b14fb', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.8', 'samcliVersion': '1.66.0', 'runtimes': ['python3.8']}}]} 2022-12-16 10:02:29,868 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)

Command stopped: "sam local invoke" 2022-12-16 10:02:30 [INFO]: Attaching debugger to SAM application...

moelasmar commented 1 year ago

Thanks @marciogoulart for raising this issue. I can see from the logs you attached that the vscode executed the sam build command and set the output to path C:\Users\GOULART\AppData\Local\Temp\aws-toolkit-vscode\vsctkmTivSZ\output and then executed the sam local invoke command but used a wrong template path C:\Users\GOULART\Documents\UnidadeD\workspace_naas\NaasVerifyLocationRepository\infra\cdk.out\VerifyLocationFunctionStack.template.json, but it should use the built template found in path C:\Users\GOULART\AppData\Local\Temp\aws-toolkit-vscode\vsctkmTivSZ\output\template.yaml.

I am not sure if you can use aws-sam as debug configuration for the template synthesized by CDK, and what is the correct configuration to be used. I will raise this issue to the correct team to check it.

marciogoulart commented 1 year ago

Hello, in that mentioned pathI don't have the yaml template, just the dependencies.

lbustelo commented 1 year ago

Are there instructions for Debugging Python lambda that looks more like this blog post for Node.

Here, the author is just setting -d in the sam invoke and that triggers the process to load debugger and wait for a connection. Then all that is needed is to use the Remove Attach from VSCode.

antoineaws commented 8 months ago

+1 to @lbustelo . I am trying to debug SAM Python locally using sam local start-api -d 5858 -t ./template.yml, the functions execute successfully but how can we (similar to Node) make the sam process wait for a debugger to get attached?

nrxlor commented 2 months ago

leave the eyes here.