amazon-web-services - AWS lambda 工作正常但我无法返回值

标签 amazon-web-services amazon-s3 post aws-lambda request

我无法让我的 lambda 返回一个值,即使代码在 return 语句之前运行良好。我的返回语句和上面的语句如下所示:

print(score)
return {
        "StatusCode": 200,
        "headers":{'dummy':'dummy'},
        "body": str(score)
    }

以下是我的 serverless.yml:

service : test-deploy

plugins:
  - serverless-python-requirements
provider:
 name: aws
 runtime: python3.6
 region : ap-south-1
 deploymentBucket:
  name : smecornerdep-package
 iamRoleStatements:
  - Effect : Allow
    Action:
     - s3:GetObject
    Resource:
     - "arn:aws:s3:::smecornerdep/*"

custom:
 pythonRequirements:
  slim: True

functions:
 app-on-book-only:
  name: app-on-book-only
  description : deploy trained lightgbm on aws lambda using serverless
  handler : run_model_l.get_predictions
  events :
   - http : POST /engine

我正在通过命令行中的 POST 到达终点,如下所示:

curl -X POST -H "Content-Type: application/json" --data @sample_common_3.json https://76pmb6z1ya.execute-api.ap-south-1.amazonaws.com/dev/engine

在我的 aws lambda 日志中,我可以看到 print(score) 的输出就在要准确计算的 return 语句上方。 aws lambda 日志中没有错误。但是,在我的终端中,我总是收到 curl 命令返回的 {"message": "Internal server error"}

我是一名数据科学家,对开发运营的概念还很陌生。请帮助我理解我的错误,并提出解决方案。

感谢阅读

最佳答案

我知道你的代码有什么问题。您在返回字典中使用了错误的语法 StatusCode 应该是 statusCode

return {
    "statusCode": 200,
    "headers":{'dummy':'dummy'},
    "body": str(score)
}

关于amazon-web-services - AWS lambda 工作正常但我无法返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64142304/

相关文章:

amazon-web-services - Amazon Cloudfront 允许所有备用域名 (CNAMES)

amazon-web-services - 我的 AWS Lambda 由 S3 对象创建触发,并发出复制对象请求。这会产生无限循环。有什么办法解决这个问题吗?

ruby-on-rails - rails 上的 ruby 。付费发表文章

amazon-web-services - 如何使用加密的DLQ向SNS添加Redrive策略

rest - 如何将 S3 用作静态网页和 EC2 作为 REST API 一起使用? (AWS)

python - ShellCommandActivity 和 python 脚本

php - 如何修复 : The difference between the request time and the current time is too large

php - 通过 HTTP $_POST 快速上传图片

html - 使 href( anchor 标记)请求 POST 而不是 GET?

java - Tomcat 管理器 : Cannot Upload Large WAR file