我正在创建无服务器架构。在那里我试图通过 api 网关打开“index.html”页面。但是在测试 Lambda 函数以发布和获取请求时。我收到错误 { "errorMessage": "'http方法'", "errorType": "KeyError", “requestId”:“edaf3570-7804-43ac-a4c8-3e6ea0aa1c40”, “堆栈跟踪”: [ “文件”/var/task/lambda_function.py,第 5 行,lambda_handler mypage = page_router(event['httpmethod'], event['quaryStringParameters'], event['formbody']) “ ] `
import json
import os, re, base64
import boto3
def lambda_handler(event, context):
mypage = page_router(event['httpmethod'], event['quaryStringParameters'], event['formbody'])
return mypage
# print("Inside lambda function")
# print(event)
def page_router(httpmethod, quaryStringParameters, formbody):
if httpmethod == 'POST':
htmlFile = open('index.html', 'w')
htmlContent = htmlFile.write()
insert_record(formbody)
return {
'statusCode': 200,
'headers': {"Content-Type":"text/html"},
'body': htmlContent,
}
if httpmethod == 'GET':
# insert_record(formbody)
htmlFile = open('confirm.html', 'r')
htmlContent = htmlFile.read()
return {
'statusCode': 200,
'headers': {"Content-Type":"text/html"},
'body': htmlContent,
# 'isBase64Encoded': False
}
def insert_record(formbody):
formbody = formbody.replace("=", "' : '")
formbody = formbody.replace("&", "' , '")
formbody = "INSERT INTO dynamodb value {'" + formbody + "'}"
client = boto3.client('studentinfo')
client.execute_statement(Statement = formbody)
我正在尝试通过“POST”方法将数据插入“index.html”页面,并且数据保存在 Dynamodb 中。通过'post'方法将数据插入“index.html”并单击'index.html'中的'submit'按钮后,它通过'GET'方法打开'confirm.html'页面。
如何解决这个问题以及我的 json 事件应该是什么?
事件中的一个键(httpmethod、queryStringParameters 和 formbody)或所有键不存在。
在方法的开头打印(事件),并在日志中查看错误。