AWS Lambda error when debugging it with VSCode and Podman
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?
@javierhersan thanks for reporting this! It looks like your message got cut off in the launch.json configuration - I can see it ends at "lambdaHandler": "app.lambda_ha but I need to see the complete configuration to understand what's happening. Could you paste the full launch.json file?
Also, when you say "it doesn't work" when debugging through VSCode, what specific error are you seeing? Is it a Podman-specific error, a connection timeout, or something else? The fact that sam local start-api works fine from the terminal but fails through the VSCode debugger suggests there might be something about how the AWS Toolkit extension is invoking Podman versus how the CLI does it directly.
A few things that would help me understand the issue better: Are you using the AWS Toolkit extension for VSCode? What version? And have you configured SAM CLI to use Podman in your settings (like setting the container runtime in ~/.aws-sam/metadata.json or through environment variables)? Sometimes the VSCode extension doesn't pick up the same Podman configuration that your terminal session uses, which could explain why CLI commands work but the debugger doesn't.
@javierhersan Do you mind providing additional information. Also, have you try using other container like docker or finch to see if the issue to specific to podman