I am accessing the following function created in lambda:
import json
import boto3
from get_json_s3 import get_json
def lambda_handler(event, context):
print(event)
jobId = event['queryStringParameters']['jobID']
try:
print(jobId)
response = get_json(None,f'{jobId}.json')
print(response)
except:
return {
'statusCode': 200,
'body': json.dumps('jobID not found')
}
print("success")
return {
'statusCode': 200,
'body': json.dumps(response)
}
get_json is defined as follows:
import json
import boto3
s3 = boto3.client('s3')
def get_json(filegroup, filename):
bucket = 'bucket name'
if filegroup!=None:
key = f'{filegroup}/{filename}'
else:
key = f'{filename}'
response = s3.get_object(Bucket = bucket, Key = key)
content = response['Body']
jsonObject = json.loads(content.read())
return jsonObject
I have created a API gateway with lambda as a proxy. I have added the invoke access and apigateway access to lambda function but I keep getting 502: Internal Server Error.
The lambda is doing the function it is supposed to do correctly as I can see from Cloud watch logs. It is being triggered correctly via APIgateway too. Only the response part is not working
question from:
https://stackoverflow.com/questions/65603137/getting-message-internal-server-error-while-invoking-aws-lambda-via-api-gatew 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…