0

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"
  ]
}
1
  • How did it go? Still unclear what you can do? Commented Jan 17, 2022 at 5:41

1 Answer 1

1

Instead of

data.encode='UTF-8'

it should be:

data.encode('UTF-8')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.