Skip to content

AWS Lambda error when debugging it with VSCode and Podman #8080

@javierhersan

Description

@javierhersan

I am executing the following AWS Lambda

  • Dockerfile:
FROM public.ecr.aws/lambda/python:3.11

COPY requirements.txt ./

RUN python3.11 -m pip install -r requirements.txt -t .

COPY app.py ./

# Command can be overwritten by providing a different command in the template directly.
CMD ["app.lambda_handler"]
  • app.py:
import json


def lambda_handler(event, context):

    return {
        "statusCode": 200,
        "body": json.dumps(
            {
                "message": "hello world",
            }
        ),
    }

When executing it directly from the terminal (already using Podman) with any of this commands it works well.

sam build
sam build --debug

sam local start-api
sam local start-api --debug

But when i try to debug it using VSCode and this configuration it doesn`t

  • .vscode/launch.json:
{
    "configurations": [
        {
            "type": "aws-sam",
            "request": "direct-invoke",
            "name": "hello_world:app.lambda_handler (python3.11)",
            "invokeTarget": {
                "target": "code",
                "projectRoot": "${workspaceFolder}/sam-app/hello_world",
                "lambdaHandler": "app.lambda_handler"
            },
            "lambda": {
                "runtime": "python3.11",
                "payload": {},
                "environmentVariables": {}
            }
        }
    ]
}

The error logs:

2025-06-05 18:54:53.463 [info] Building codeuri: C:/Javier/Projects/Reinsurance Studio/Repositories/GRE/Gre-Data-Call-lambdas/sam-app/hello_world runtime: python3.11 architecture: x86_64 functions: helloworld
2025-06-05 18:54:53.814 [info] Running PythonPipBuilder:ResolveDependencies
2025-06-05 18:55:00.457 [info] Running PythonPipBuilder:CopySource
2025-06-05 18:55:00.486 [info] Build Succeeded
2025-06-05 18:55:00.487 [info] Built Artifacts  : ..\..\..\..\..\..\J.HERNANDEZSANCHEZ\AppData\Local\Temp\aws-toolkit-vscode\vsctkb85f2ff9\output
Built Template   : ..\..\..\..\..\..\J.HERNANDEZSANCHEZ\AppData\Local\Temp\aws-toolkit-vscode\vsctkb85f2ff9\output\template.yaml

Commands you can use next

=========================

[*] Validate SAM template: sam validate

[*] Invoke Function: sam local invoke -t ..\..\..\..\..\..\J.HERNANDEZSANCHEZ\AppData\Local\Temp\aws-toolkit-vscode\vsctkb85f2ff9\output\template.yaml

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

[*] Deploy: sam deploy --guided --template-file ..\..\..\..\..\..\J.HERNANDEZSANCHEZ\AppData\Local\Temp\aws-toolkit-vscode\vsctkb85f2ff9\output\template.yaml
2025-06-05 18:55:10.555 [info] Invoking app.lambda_handler (python3.11)
2025-06-05 18:55:10.576 [info] Local image was not found.
2025-06-05 18:55:10.577 [info] Removing rapid images for repo public.ecr.aws/sam/emulation-python3.11
2025-06-05 18:55:10.622 [info] Building image...
2025-06-05 18:55:20.018 [info] Using local image: public.ecr.aws/lambda/python:3.11-rapid-x86_64.

Mounting C:\Users\J1EE5~1.HER\AppData\Local\Temp\aws-toolkit-vscode\vsctkb85f2ff9\output\helloworld as /var/task:ro,delegated, inside runtime container
2025-06-05 18:55:22.040 [info] START RequestId: f3f075e7-1cde-4f3a-8517-b8ca8afccd25 Version: $LATEST
/var/lang/bin/python3.11: can't open file '/tmp/lambci_debug_files/py_debug_wrapper.py': [Errno 2] No such file or directory
05 Jun 2025 16:55:21,781 [ERROR] (rapid) Init failed InvokeID= error=Runtime exited with error: exit status 2
05 Jun 2025 16:55:21,781 [ERROR] (rapid) Invoke failed error=Runtime exited with error: exit status 2 InvokeID=ec11fc9c-0f3c-4b66-9d27-76fe970fb146
05 Jun 2025 16:55:21,782 [ERROR] (rapid) Invoke DONE failed: Sandbox.Failure
2025-06-05 18:55:22.795 [info] 
2025-06-05 18:55:25.443 [info] 
2025-06-05 18:55:25.444 [info] Command stopped: "sam local invoke"

Does anyone know why it's not working?

Metadata

Metadata

Assignees

No one assigned

    Labels

    need-customer-responseWaiting for customer responsestage/needs-triageAutomatically applied to new issues and PRs, indicating they haven't been looked at.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions