我正在嘗試從 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 插入命令中的錯誤。我嘗試了很多次來修復它。但無法這樣做。
誰能讓我知道如何糾正它?
任何幫助,將不勝感激。
uj5u.com熱心網友回復:
您缺少右括號:
pymysql_insert = cursor.execute("INSERT INTO rchd2(uniquedataid, platformdetails, systemname, processorname, architecturaldetail, nodename) VALUES (%s, %s, %s, %s, %s, %s)")
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/412512.html
標籤:
