I'm have something testdataset.csv under the S3 bucket named testprojectbucket
. Inside there is testdataset.csv
Here is what I've done:
I've granted access to my lambda function with
AmazonS3ReadOnlyAccess
My lambda function has the basic lambda permissions
I've created an HTTP API via API gateway using the ANY method and integrated it with the lambda function
However, when I tried to invoke the API call in the machine it says
Internal Server Error
I suspect it is my lambda function.
Here is my code:
import boto3
import csv
import io
s3 = boto3.client('s3')
bucket = 'testprojectbucket'
object_key = 'testdataset.csv'
def lambda_handler(event, context):
try:
# Get the object from S3
response = s3.get_object(Bucket=bucket, Key=object_key)
content = response['Body'].read().decode('utf-8')
results = []
# Parse CSV
csv_reader = csv.DictReader(io.StringIO(content))
for row in csv_reader:
results.append(row)
return {
"statusCode": 200,
"body": results
}
except Exception as e:
return {
"statusCode": 500,
"error": str(e)
}
Can anyone help? I am new to Cloud Computing in General.