【问题标题】:AWS Lambda is returning empty jsonAWS Lambda 返回空 json
【发布时间】:2021-08-22 22:41:58
【问题描述】:

我试图在 AWS lambda 中返回 json 字符串。此代码在我的本地机器上运行,但在 AWS lambda 中返回空 json 字符串。 下面给出了我的代码的相关部分

import json
import time as time
import pandas as pd                        
from pytrends.request import TrendReq #to connect to google trends and request trends
from datetime import datetime
from datetime import date


def lambda_handler(event, context):
   #irrelevant parts of code here
   #......
    DfmergedTopJson = DfmergedTop.to_json(orient="records") #DfmergedTop is dataframe
    DfmergedRiseJson = DfmergedRise.to_json(orient="records") #DfmergedRiseJson is a df 
    dfjson = df.to_json(orient="records")
    return DfmergedTopJson, DfmergedRiseJson

输出是

Test Event Name
EventGoogle
Response
[
  "[]",
  "[]"
]

实际上我的输出是一个很长的 json 字符串,我在本地机器上成功打印了它。 请为此建议我可能的解决方案。

【问题讨论】:

    标签: python json python-3.x amazon-web-services aws-lambda


    【解决方案1】:
    1. 您的 Lambda 函数真的产生了您期望的值吗?使用 print 函数记录运行时变量,即: DfmergedTopJsonDfmergedRiseJson 到 CloudWatch Log,然后评估日志。

    2. 您可能还想记录event 对象 要查看发送到您的 Lambda 函数的内容,内容可能不是 你所期望的。

    https://docs.aws.amazon.com/lambda/latest/dg/python-logging.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-07
      • 2020-03-16
      • 2019-05-03
      • 2021-11-01
      • 2020-07-30
      • 2021-02-07
      • 2018-10-04
      相关资源
      最近更新 更多