GET 有效,但所有其他请求都会给出“API 网关:内部服务器错误”

问题描述 投票:0回答:1

我在这里看到了类似问题的答案。但这对解决我的问题没有帮助

当我在 Postman 上执行 GET 请求时,我得到“GET TEST”响应,但是当我执行任何其他类型的请求时,我得到“API 网关:内部服务器错误”

我的资源设置了各种方法类型

我有一个带有以下代码的 lambda 函数(我删除了游标/数据库凭证代码):

import json
import mysql.connector

def lambda_handler(event, context):

    http_method = event.get('httpMethod')
    response = None  
    
    if http_method == "GET":
        response = getFunction(cursor, event)
    elif http_method == "POST":
         response = postFunction(cursor, event) 
    elif http_method == "PUT":
         response = putFunction(cursor, event)
    elif http_method == "DELETE":
         response = deleteFunction(cursor, event) 
        
  
    return {
        "statusCode": 200,
        "body": json.dumps({
            "event": event,
            "response": response
        })
    }

def getFunction(cursor, event):
    return "GET TEST"
    
def postFunction():
    return "POST TEST"
    
def putFunction():
    return "PUT TEST"

def deleteFunction():
    return "DELETE TEST"
python amazon-web-services aws-lambda aws-api-gateway
1个回答
0
投票

天哪,我是个菜鸟。

我查看了 Cloudwatch 日志,发现我的函数没有参数。

© www.soinside.com 2019 - 2024. All rights reserved.