I want to upload the JSON file to the s3 bucket with the help of lambda. I have added pandas to the layer already. there is no issue with permissions. can also if also want to upload as csv how can I do that.
import pandas as pd
# import json
import json
import boto3
# store the URL in url
s3 = boto3.client('s3')
def lambda_handler(event, context):
bucket ='aws-simplified-transactions420'
url = 'https://house-stock-watcher-data.s3-us-west-2.amazonaws.com/data/all_transactions.json'
df = pd.read_json(url)
data = df.to_json()
fileName = 'data' + '.json '
uploadByteStream = bytes(json.dumps(data.encode='UTF-8'))
s3.put_object(Bucket=bucket, Key=fileName, Body=uploadByteStream)
print('Put Complete')
the error message
Response
{
"errorMessage": "Syntax error in module 'lambda_function': keyword can't be an expression (lambda_function.py, line 16)",
"errorType": "Runtime.UserCodeSyntaxError",
"stackTrace": [
" File \"/var/task/lambda_function.py\" Line 16\n uploadByteStream = bytes(json.dumps(data.encode='UTF-8'))\n"
]
}