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
Here is the common issues which might be able to help you diagnose the issue.
I recommend you to enable logging feature on API Gateway side or you can use the test invoke feature on API Gateway console using this doc .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.