API URL返回Null

时间:2018-12-16 00:44:21

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

...通过以下政策创建了一个名为XYZ的IAM角色

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "lambda:InvokeFunction",
            "Resource": "*"
        }
    ]
}

...更新了信任关系XYZ角色,以同时包含lambda和API网关

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "Service": [
          "lambda.amazonaws.com",
          "apigateway.amazonaws.com"
        ]
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

...创建了Lambda函数并附加了角色XYZ。我可以成功执行Lambda函数。

from __future__ import print_function

import json
import datetime

def lambda_handler(event, context):
    ts = datetime.datetime.now().timestamp()
    print (ts)
    print ("Hello")
    #raise Exception('Something went wrong')

......将API网关附加到Lambda函数。我将XYZ指定为该方法的执行角色。

调用API时我得到“空”

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您的lambda_handler未返回任何内容。试试:

def lambda_handler(event, context):
    return {
        'statusCode': 200,
        'body': 'Hello'
    }