sst / ion

SST v3
https://sst.dev
MIT License
1.91k stars 226 forks source link

Print Statements In Python Lambda Aren't Captured Constantly #1106

Open samueltanner opened 1 week ago

samueltanner commented 1 week ago

SST v3.1.10 with a Python3.11 lambda on Mac M2 Max Running Sonoma 14.2.1

Description of Issue: When I invoke this function from the sst console, the first instance after the initial build, I will see in the functions tab of my terminal that the function was built. Back in the sst console I will see a blank log. On the second invocation, I will get either: A. a blank response (none of the print statements), B. Just the first print statement, C. All of the print statements. Typically on the third invocation I will then get a blank response, and on the 4th will get one of the options A-C again.

If I invoke the function using Postman and the lambda url, I will see all the logs in my terminal but I will not see consistent logs in the sst console.

Constructor Definition:

const grantAiLambda = new sst.aws.Function("GGGrantAiAssistant", {
      handler: "packages/functions/lambda/grantAi/index.handler",
      runtime: "python3.11",
      timeout: "10 minutes",
      transform: {
        function: {
          name: `GGGrantAiAssistant${$app.stage}`,
        },
      },
      url: true,
    })

packages/functions/grantAi:

 grantAi
├── .python-version
├── README.md
├── index.py
├── pyproject.toml
├── sst_env.pyi
└── uv.lock

Handler Code:

import requests
import boto3
import os

env_vars = os.environ

def handler(event, context):
    print(env_vars)
    print(event)
    print(context)
jayair commented 1 week ago

Is this for sst dev?

samueltanner commented 1 week ago

Is this for sst dev?

Yeah it is.