aws / aws-toolkit-vscode

Amazon Q, CodeCatalyst, Local Lambda debug, SAM/CFN syntax, ECS Terminal, AWS resources
https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.amazon-q-vscode
Apache License 2.0
1.5k stars 424 forks source link

Issues while Debugging CDK Lambda with SAM #3101

Open ThuF opened 1 year ago

ThuF commented 1 year ago

System details (run the AWS: About Toolkit command)

Question

Hi,

I'm trying to debug a lambda function with an aws-sam debug config for VSCode. The lambda function is part of an AWS CDK deployment. The function is fairly simple, it just reads some data from a DynamoDB table:

import {
    DynamoDBClient,
    ScanCommand
} from "@aws-sdk/client-dynamodb";

const TABLE_NAME = process.env.TABLE_NAME;

export const handler = async (event) => {
    const dynamoDB = new DynamoDBClient();
    try {
        switch (event.requestContext.http.method.toUpperCase()) {
            case "GET":
                return listEntities(dynamoDB);
            default:
                return "Not supported operation";
        }
    } catch (e) {
        return e;
    }
}

const listEntities = async (dynamoDB) => {
    const command = new ScanCommand({
        TableName: TABLE_NAME
    });
    const result = await dynamoDB.send(command);
    return result.Items.map(e => fromDatabaseEntity(e));
}

const fromDatabaseEntity = (item) => {
    return {
        id: item?.id?.S,
        name: item?.name?.S
    };
}

After synthesizing the CDK (cdk synth) and executing the following command via SAM, I'm able to run the lambda locally (the lambda is exposed at the correct path and the data is fetched from the remote AWS DynamoDB table):

sam local start-api -t cdk.out/ApplicationStack.template.json --profile admin

However, if I try to debug the the lambda function with the following launch config, I got this:

{
    "configurations": [
        {
            "type": "aws-sam",
            "request": "direct-invoke",
            "name": "my-service:src/index.handler (nodejs16.x)",
            "invokeTarget": {
                "target": "code",
                "projectRoot": "${workspaceFolder}/apps/my-service",
                "lambdaHandler": "src/index.handler"
            },
            "lambda": {
                "runtime": "nodejs16.x",
                "payload": {
                    "json": {
                        "requestContext": {
                            "http": {
                                "method": "GET"
                            }
                        }
                    }
                },
                "environmentVariables": {
                    "TABLE_NAME": "my-demo"
                }
            },
            "sam": {
                "localArguments": [
                    "--profile",
                    "admin",
                    "--region",
                    "eu-central-1"
                ]
            }
        }
    ]
}

Note: I was forced to use sam.localArguments to provide the profile and the region, as for some reason when setting aws.credentials I got the following in the log Loading AWS credentials from session with profile 'None'.

Here is the log from the debug session:

2023-01-16 15:05:37 [VERBOSE]: SAM debug: config: "my-service:src/index.handler (nodejs16.x)"
2023-01-16 15:05:37 [INFO]: Preparing to debug locally: Lambda "src/index.handler"
2023-01-16 15:05:37 [INFO]: Building SAM application...
2023-01-16 15:05:37 [VERBOSE]: running: (not started) [/opt/homebrew/bin/sam build --debug --build-dir /tmp/aws-toolkit-vscode/vsctkiKjjr4/output --template /tmp/aws-toolkit-vscode/vsctkiKjjr4/app___vsctk___template.yaml --base-dir /Users/thuf/Documents/git/my-project/apps/my-service]
2023-01-16 15:05:37 [INFO]: Command: (not started) [/opt/homebrew/bin/sam build --debug --build-dir /tmp/aws-toolkit-vscode/vsctkiKjjr4/output --template /tmp/aws-toolkit-vscode/vsctkiKjjr4/app___vsctk___template.yaml --base-dir /Users/thuf/Documents/git/my-project/apps/my-service]
2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,162 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-01-16 15:05:38,163 | Using config file: samconfig.toml, config environment: default

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,163 | Expand command line arguments to:
2023-01-16 15:05:38,163 | --template_file=/tmp/aws-toolkit-vscode/vsctkiKjjr4/app___vsctk___template.yaml --build_dir=/tmp/aws-toolkit-vscode/vsctkiKjjr4/output --base_dir=/Users/thuf/Documents/git/my-project/apps/my-service --cache_dir=.aws-sam/cache 

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,455 | 'build' command is called

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,456 | No Parameters detected in the template

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,467 | There is no customer defined id or cdk path defined for resource myservice, so we will use the resource logical id as the resource id

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,467 | 0 stacks found in the template
2023-01-16 15:05:38,467 | No Parameters detected in the template

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,474 | There is no customer defined id or cdk path defined for resource myservice, so we will use the resource logical id as the resource id

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,474 | 1 resources found in the stack 
2023-01-16 15:05:38,474 | Found Serverless function with name='myservice' and CodeUri='/Users/thuf/Documents/git/my-project/apps/my-service'

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,476 | 1 resources found in the stack 

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,476 | Found Serverless function with name='myservice' and CodeUri='/Users/thuf/Documents/git/my-project/apps/my-service'

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,476 | Instantiating build definitions

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,476 | No previous build graph found, generating new one
2023-01-16 15:05:38,476 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(nodejs16.x, /Users/thuf/Documents/git/my-project/apps/my-service, Zip, , 94645985-7b1d-4b22-93fd-663ec89f671b, {}, {}, x86_64, []), Function: Function(function_id='myservice', name='myservice', functionname='myservice', runtime='nodejs16.x', memory=None, timeout=None, handler='src/index.handler', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='/Users/thuf/Documents/git/my-project/apps/my-service', environment={'Variables': {'TABLE_NAME': 'my-demo'}}, rolearn=None, layers=[], events=None, metadata={'SamResourceId': 'myservice'}, inlinecode=None, codesign_config_arn=None, architectures=None, function_url_config=None, stack_path=''))

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,477 | Building codeuri: /Users/thuf/Documents/git/my-project/apps/my-service runtime: nodejs16.x metadata: {} architecture: x86_64 functions: myservice

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,477 | Building to following folder /private/tmp/aws-toolkit-vscode/vsctkiKjjr4/output/myservice

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,478 | Loading workflow module 'aws_lambda_builders.workflows'

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,481 | Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)'

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,483 | Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,484 | Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)'

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,486 | Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)'

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,488 | Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)'

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,490 | Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)'

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,492 | Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,493 | Registering workflow 'CustomMakeBuilder' with capability 'Capability(language='provided', dependency_manager=None, application_framework=None)'

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,495 | Registering workflow 'NodejsNpmEsbuildBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm-esbuild', application_framework=None)'

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,495 | Found workflow 'NodejsNpmBuilder' to support capabilities 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,495 | Running workflow 'NodejsNpmBuilder'

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,495 | Running NodejsNpmBuilder:NpmPack
2023-01-16 15:05:38,495 | NODEJS packaging file:/Users/thuf/Documents/git/my-project/apps/my-service to /var/folders/cy/t93543bs285ckm7_lycqg5t80000gn/T/tmp8t_cp5yn

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,495 | executing NPM: ['npm', 'pack', '-q', 'file:/Users/thuf/Documents/git/my-project/apps/my-service']

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,905 | NODEJS packed to tires-my-service-1.0.0.tgz

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,906 | NODEJS extracting to /var/folders/cy/t93543bs285ckm7_lycqg5t80000gn/T/tmp8t_cp5yn/unpacked

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,907 | NodejsNpmBuilder:NpmPack succeeded

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,907 | Running NodejsNpmBuilder:CopyNpmrcAndLockfile
2023-01-16 15:05:38,907 | NodejsNpmBuilder:CopyNpmrcAndLockfile succeeded
2023-01-16 15:05:38,907 | Running NodejsNpmBuilder:CopySource

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,907 | Creating target folders at /private/tmp/aws-toolkit-vscode/vsctkiKjjr4/output/myservice
2023-01-16 15:05:38,907 | Copying directory metadata from source (/var/folders/cy/t93543bs285ckm7_lycqg5t80000gn/T/tmp8t_cp5yn/unpacked/package) to destination (/private/tmp/aws-toolkit-vscode/vsctkiKjjr4/output/myservice)

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,908 | Copying source file (/var/folders/cy/t93543bs285ckm7_lycqg5t80000gn/T/tmp8t_cp5yn/unpacked/package/package.json) to destination (/private/tmp/aws-toolkit-vscode/vsctkiKjjr4/output/myservice/package.json)

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,908 | Creating target folders at /private/tmp/aws-toolkit-vscode/vsctkiKjjr4/output/myservice/src

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,908 | Copying directory metadata from source (/var/folders/cy/t93543bs285ckm7_lycqg5t80000gn/T/tmp8t_cp5yn/unpacked/package/src) to destination (/private/tmp/aws-toolkit-vscode/vsctkiKjjr4/output/myservice/src)

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,908 | Copying source file (/var/folders/cy/t93543bs285ckm7_lycqg5t80000gn/T/tmp8t_cp5yn/unpacked/package/src/index.js) to destination (/private/tmp/aws-toolkit-vscode/vsctkiKjjr4/output/myservice/src/index.js)

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,908 | NodejsNpmBuilder:CopySource succeeded

2023-01-16 15:05:38 [VERBOSE]: stderr: 2023-01-16 15:05:38,908 | Running NodejsNpmBuilder:NpmInstall
2023-01-16 15:05:38,908 | NODEJS installing in: /private/tmp/aws-toolkit-vscode/vsctkiKjjr4/output/myservice
2023-01-16 15:05:38,908 | executing NPM: ['npm', 'install', '-q', '--no-audit', '--no-save', '--unsafe-perm', '--production']

2023-01-16 15:05:40 [VERBOSE]: stderr: 2023-01-16 15:05:40,325 | NodejsNpmBuilder:NpmInstall succeeded

2023-01-16 15:05:40 [VERBOSE]: stderr: 2023-01-16 15:05:40,326 | Running NodejsNpmBuilder:CleanUpNpmrc
2023-01-16 15:05:40,326 | NodejsNpmBuilder:CleanUpNpmrc succeeded
2023-01-16 15:05:40,326 | Running NodejsNpmBuilder:LockfileCleanUp
2023-01-16 15:05:40,326 | .package-lock cleanup in: /private/tmp/aws-toolkit-vscode/vsctkiKjjr4/output/myservice
2023-01-16 15:05:40,326 | NodejsNpmBuilder:LockfileCleanUp succeeded

2023-01-16 15:05:40 [VERBOSE]: stderr: 2023-01-16 15:05:40,327 | There is no customer defined id or cdk path defined for resource myservice, so we will use the resource logical id as the resource id

2023-01-16 15:05:40 [VERBOSE]: stderr: 2023-01-16 15:05:40,327 | 1 resources found in the stack 
2023-01-16 15:05:40,327 | Found Serverless function with name='myservice' and CodeUri='/Users/thuf/Documents/git/my-project/apps/my-service'

2023-01-16 15:05:40 [VERBOSE]: stdout: 
Build Succeeded

2023-01-16 15:05:40 [VERBOSE]: stdout: 
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

2023-01-16 15:05:40 [VERBOSE]: stderr: 2023-01-16 15:05:40,362 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics

2023-01-16 15:05:40 [VERBOSE]: stderr: 2023-01-16 15:05:40,362 | Unable to find Click Context for getting session_id.

2023-01-16 15:05:40 [VERBOSE]: stderr: 2023-01-16 15:05:40,363 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': 'a6c23300-6f66-43ee-ae45-fed91fe59e06', 'installationId': 'd46ff82d-5449-45d2-b2c9-f04215b972c6', 'sessionId': '04dd62fd-4dc2-4ae5-a65d-21cc2e3cc8d2', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.15', 'samcliVersion': '1.60.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName': 'ceb9790bc0a33bd64591592c9fab4b4ee88d7265e3db588da216e838814afa8f', 'initialCommit': None}, 'duration': 2199, 'exitReason': 'success', 'exitCode': 0}}]}

2023-01-16 15:05:40 [VERBOSE]: stderr: 2023-01-16 15:05:40,363 | Sending Telemetry: {'metrics': [{'events': {'requestId': '18eaeb5e-5f4a-4fb3-bb77-0231e3b66307', 'installationId': 'd46ff82d-5449-45d2-b2c9-f04215b972c6', 'sessionId': '04dd62fd-4dc2-4ae5-a65d-21cc2e3cc8d2', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.15', 'samcliVersion': '1.60.0', 'metricSpecificAttributes': {'events': [{'event_name': 'BuildWorkflowUsed', 'event_value': 'nodejs-npm', 'thread_id': 8649882240, 'time_stamp': '2023-01-16 13:05:38.477'}, {'event_name': 'BuildFunctionRuntime', 'event_value': 'nodejs16.x', 'thread_id': 8649882240, 'time_stamp': '2023-01-16 13:05:40.328'}]}}}]}

2023-01-16 15:05:41 [VERBOSE]: stderr: 2023-01-16 15:05:41,106 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
2023-01-16 15:05:41,107 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)

2023-01-16 15:05:41 [INFO]: Build complete.
2023-01-16 15:05:41 [INFO]: Starting SAM application locally
2023-01-16 15:05:41 [DEBUG]: localLambdaRunner.invokeLambdaFunction: my-service:src/index.handler (nodejs16.x)
2023-01-16 15:05:41 [INFO]: AWS.running.command
2023-01-16 15:05:41 [INFO]: Command: (not started) [/opt/homebrew/bin/sam local invoke --debug myservice --template /tmp/aws-toolkit-vscode/vsctkiKjjr4/output/template.yaml --event /tmp/aws-toolkit-vscode/vsctkiKjjr4/event.json --env-vars /tmp/aws-toolkit-vscode/vsctkiKjjr4/env-vars.json -d 5860 --profile admin --region eu-central-1] (running processes: 1)
2023-01-16 15:05:41 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:05:41,649 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics

2023-01-16 15:05:41 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:05:41,649 | Using config file: samconfig.toml, config environment: default
2023-01-16 15:05:41,649 | Expand command line arguments to:
2023-01-16 15:05:41,649 | --template_file=/tmp/aws-toolkit-vscode/vsctkiKjjr4/output/template.yaml --event=/tmp/aws-toolkit-vscode/vsctkiKjjr4/event.json --env_vars=/tmp/aws-toolkit-vscode/vsctkiKjjr4/env-vars.json --debug_port=(5860,) --function_logical_id=myservice --no_event --layer_cache_basedir=/Users/thuf/.aws-sam/layers-pkg --container_host=localhost --container_host_interface=127.0.0.1 
2023-01-16 15:05:41,649 | local invoke command is called

2023-01-16 15:05:41 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:05:41,651 | No Parameters detected in the template

2023-01-16 15:05:41 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:05:41,659 | Sam customer defined id is more priority than other IDs. Customer defined id for resource myservice is myservice

2023-01-16 15:05:41 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:05:41,659 | 0 stacks found in the template
2023-01-16 15:05:41,659 | No Parameters detected in the template

2023-01-16 15:05:41 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:05:41,666 | Sam customer defined id is more priority than other IDs. Customer defined id for resource myservice is myservice

2023-01-16 15:05:41 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:05:41,667 | 1 resources found in the stack 
2023-01-16 15:05:41,667 | Found Serverless function with name='myservice' and CodeUri='myservice'
2023-01-16 15:05:41,667 | --base-dir is not presented, adjusting uri myservice relative to /tmp/aws-toolkit-vscode/vsctkiKjjr4/output/template.yaml

2023-01-16 15:05:41 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:05:41,682 | Found one Lambda function with name 'myservice'

2023-01-16 15:05:41 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:05:41,682 | Invoking src/index.handler (nodejs16.x)
2023-01-16 15:05:41,682 | Environment variables data found for specific function in standard format
2023-01-16 15:05:41,682 | Loading AWS credentials from session with profile 'admin'

2023-01-16 15:05:41 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:05:41,689 | Resolving code path. Cwd=/tmp/aws-toolkit-vscode/vsctkiKjjr4/output, CodeUri=/tmp/aws-toolkit-vscode/vsctkiKjjr4/output/myservice

2023-01-16 15:05:41 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:05:41,689 | Resolved absolute path to code is /tmp/aws-toolkit-vscode/vsctkiKjjr4/output/myservice
2023-01-16 15:05:41,690 | Code /tmp/aws-toolkit-vscode/vsctkiKjjr4/output/myservice is not a zip/jar file

2023-01-16 15:05:41 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:05:41,711 | Skip pulling image and use local one: public.ecr.aws/sam/emulation-nodejs16.x:rapid-1.60.0-x86_64.

2023-01-16 15:05:41 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:05:41,711 | Mounting /tmp/aws-toolkit-vscode/vsctkiKjjr4/output/myservice as /var/task:ro,delegated inside runtime container

2023-01-16 15:05:42 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:05:42,111 | Setting up SIGTERM interrupt handler

2023-01-16 15:05:42 [VERBOSE]: SAM: pid 45411: stderr: START RequestId: 5877b65a-2df6-4856-9521-ffc0b43f0625 Version: $LATEST

2023-01-16 15:05:42 [VERBOSE]: SAM: pid 45411: stderr: Debugger listening on ws://0.0.0.0:5860/137a2672-fd65-41b4-b2c7-04c3d7c1e9b8
For help, see: https://nodejs.org/en/docs/inspector

2023-01-16 15:05:42 [VERBOSE]: SAM: pid 45411: local SAM app is ready for debugger to attach
2023-01-16 15:05:42 [INFO]: Waiting for SAM application to start...
2023-01-16 15:05:42 [DEBUG]: localLambdaRunner.attachDebugger: startDebugging with config: {
  "name": "my-service:src/index.handler (nodejs16.x)",
  "invokeTarget": {
    "target": "code",
    "projectRoot": "/Users/thuf/Documents/git/my-project/apps/my-service",
    "lambdaHandler": "src/index.handler",
    "templatePath": "/tmp/aws-toolkit-vscode/vsctkiKjjr4/app___vsctk___template.yaml"
  }
}
2023-01-16 15:05:42 [INFO]: Attaching debugger to SAM application...
2023-01-16 15:05:42 [VERBOSE]: SAM: pid 45411: stderr: Debugger attached.

2023-01-16 15:05:42 [INFO]: Debugger attached
2023-01-16 15:05:42 [VERBOSE]: SAM: debug session: "my-service:src/index.handler (nodejs16.x)" / 9f81f702-b488-4ffb-ac8f-31205b8fa9d1
2023-01-16 15:05:42 [DEBUG]: telemetry: emitted metric "lambda_invokeLocal"
2023-01-16 15:05:59 [VERBOSE]: SAM: pid 45411: stderr: END RequestId: 5877b65a-2df6-4856-9521-ffc0b43f0625

2023-01-16 15:05:59 [VERBOSE]: SAM: pid 45411: stderr: REPORT RequestId: 5877b65a-2df6-4856-9521-ffc0b43f0625   Init Duration: 1.48 ms  Duration: 17344.05 ms   Billed Duration: 17345 ms   Memory Size: 128 MB Max Memory Used: 128 MB 

2023-01-16 15:05:59 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:05:59,749 | Cleaning all decompressed code dirs

2023-01-16 15:05:59 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:05:59,797 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '0477b877-cd5b-4ace-a7cb-cf67a2d7b063', 'installationId': 'd46ff82d-5449-45d2-b2c9-f04215b972c6', 'sessionId': 'bef3081c-bf88-431a-ac1b-37af638cd8fc', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.15', 'samcliVersion': '1.60.0', 'awsProfileProvided': True, 'debugFlagProvided': True, 'region': 'eu-central-1', 'commandName': 'sam local invoke', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName': 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'initialCommit': None}, 'duration': 18147, 'exitReason': 'success', 'exitCode': 0}}]}

2023-01-16 15:06:00 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:06:00,451 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)

2023-01-16 15:06:00 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:06:00,451 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-01-16 15:06:00,451 | Sending Telemetry: {'metrics': [{'runtimeMetric': {'requestId': '2736febd-5de1-477f-ab29-57e5dc0b1e19', 'installationId': 'd46ff82d-5449-45d2-b2c9-f04215b972c6', 'sessionId': 'bef3081c-bf88-431a-ac1b-37af638cd8fc', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.15', 'samcliVersion': '1.60.0', 'runtimes': ['nodejs16.x']}}]}

2023-01-16 15:06:01 [VERBOSE]: SAM: pid 45411: stderr: 2023-01-16 15:06:01,105 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)

2023-01-16 15:06:01 [VERBOSE]: SAM: command exited (code: 0): PID 45411: [/opt/homebrew/bin/sam local invoke --debug myservice --template /tmp/aws-toolkit-vscode/vsctkiKjjr4/output/template.yaml --event /tmp/aws-toolkit-vscode/vsctkiKjjr4/event.json --env-vars /tmp/aws-toolkit-vscode/vsctkiKjjr4/env-vars.json -d 5860 --profile admin --region eu-central-1]

Regards, Yordan

justinmk3 commented 1 year ago

Thank you for the thoughtful bug report!

  • I'm able to debug until line 26 (const result = await dynamoDB.send(command);), where the DynamoDB table is being queried.
  • After I press Step Over or Continue with breakpoint on the next line, the debug session suddenly stops and I don't get the results from the DynamoDB.
ThuF commented 1 year ago

Hi @justinmk3

No, it seems that the process exits. Instead of performing a get query, I've tried to insert records in the DynamoDB table - the process exits and there are no records in the table. Also I've tried to console.log() or writeFileSync() after the call to the DynamoDB, but nothing happens.

All I get is the following message in the Debug Console:

END RequestId: dd2ce95f-bc80-4153-aa8d-8ec01497b924
REPORT RequestId: dd2ce95f-bc80-4153-aa8d-8ec01497b924  Init Duration: 2.56 ms  Duration: 26659.14 ms   Billed Duration: 26660 ms   Memory Size: 128 MB Max Memory Used: 128 MB 

I've also tried to List Buckets from S3, but it's the same behaviour.

I don't have installed WebStorm, could give it a try.

Regards, Yordan