从 S3 读取 JSON 并通过 Lambda 将其上传到 RDS

Read JSON from S3 and upload it to RDS using Lambda through

我正在尝试从 S3 读取 JSON 并使用 Lambda 将其上传到 RDS。 Lambda中的代码如下:

import json
import boto3
import pymysql
s3_client = boto3.client('s3')
def lambda_handler(event, context):
    bucket = event['Records']['0']['s3']['bucket']['name']
    json_file_name = event['Records'][0]['s3']['object']['key']
    json_object = s3_client.get_object(Bucket=bucket,Key=json_file_name)
    jsonFileReader = json_object['Body'].read()
    jsonDict = json.loads(jsonFileReader)
    results = []
    for item in (jsonDict):
         results.append(row.values())
    print(results)
    conn = pymysql.connect(host = 'rchd.cypgvdgyrj6p.us-east-1.rds.amazonaws.com',user = 'rchd',passwd = 'rchdrchd',db = 'rchd')
    cursor = conn.cursor()
    pymysql_insert = cursor.execute("INSERT INTO rchd2(uniquedataid, platformdetails, systemname, processorname, architecturaldetail, nodename) VALUES (%s, %s, %s, %s, %s, %s)"
    cursor.execute(pymysql_insert,results)
    conn.commit()
    cursor.close()
    conn.close()
    print(cursor.rowcount, "record inserted successfully into employee table")
    return {
        'statusCode' : 200,
        #'body' json.dumps('hello from lambda!')
       
    }

但是,Lambda 在 Line 18 中给出了以下错误:

Response
{
  "errorMessage": "Syntax error in module 'lambda_function': invalid syntax (lambda_function.py, line 18)",
  "errorType": "Runtime.UserCodeSyntaxError",
  "requestId": "52039e38-4d6a-4a6f-a29f-b47ae91c7f37",
  "stackTrace": [
    "  File \"/var/task/lambda_function.py\" Line 18\n        cursor.execute(pymysql_insert,results)\n"
  ]
}

Function Logs
START RequestId: 52039e38-4d6a-4a6f-a29f-b47ae91c7f37 Version: $LATEST
[ERROR] Runtime.UserCodeSyntaxError: Syntax error in module 'lambda_function': invalid syntax (lambda_function.py, line 18)
Traceback (most recent call last):
  File "/var/task/lambda_function.py" Line 18
        cursor.execute(pymysql_insert,results)END RequestId: 52039e38-4d6a-4a6f-a29f-b47ae91c7f37

基于错误,我认为它在我的 SQL 插入命令中。我尝试了很多次来修复它。却做不到。

谁能告诉我如何更正它?

如有任何帮助,我们将不胜感激。

您缺少右括号:

    pymysql_insert = cursor.execute("INSERT INTO rchd2(uniquedataid, platformdetails, systemname, processorname, architecturaldetail, nodename) VALUES (%s, %s, %s, %s, %s, %s)")