I wrote a lambda function to download the csv file to s3 and created API Gateway
import os
import uuid
import boto3
from botocore.exceptions import ClientError
SECRET_KEY = os.environ["SECRET_KEY"]
ACCESS_KEY = os.environ["ACCESS_KEY"]
def lambda_handler(event, context):
# TODO implement
bucket = event['bucket']
object_name = '{}.csv'.format(uuid.uuid1())
file_name = event['filename']
s3_client = boto3.client('s3', aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY)
try:
response = s3_client.upload_file(file_name, bucket, object_name)
except ClientError as e:
logging.error(e)
return e
return True
When I run this code using the test event directly through the aws interface
test case
{
"bucket": "testcsvupload-drv-cvbx",
"filename": "file.csv",
"key3": "value3"
}
I got successful result. But then I trying using curl
request fron linux console
curl -X POST https://tvomerrrcfa.execute-api.us-east-1.amazonaws.com/file_to_s3 -H "Content-Type: multipart/form-data" -F 'filename=@/home/y700/projects/start/file.csv'
I get an error
{"message": "Could not parse request body into json: Unexpected character (\'-\' (code 45)) in numeric value: expected digit (0-9) to follow minus sign, for valid numeric value\n at [Source: (byte[])\"--------------------------e6b7a9fa3c5b61d0\r\nContent-Disposition: form-data; name=\"filename\"; filename=\"file.csv\"\r\nContent-Type: application\/octet-stream\r\n\r\nname,surname,age\nTim,Bert,19\nHelen,Glad,23\n\r\n--------------------------e6b7a9fa3c5b61d0--\r\n\"; line: 1, column: 3]"}
file.csv
name,surname,age
Tim,Bert,19
Helen,Glad,23
What am I doing wrong? And why is json referenced in the error?