I'm having a lambda function which makes use of Graphql and webscraping to return some data as response. Sometimes it works without giving an error like 502, sometimes it doesn't. To me it looks like the 502 errors are completely random, because I send the same requests with the same data all the time.
My timeout is set to 5 minutes in AWS console.
These are the errors I get (in browser):
Failed to load [BIG URL] No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '[mydomainurl]' is therefore not allowed access. The response had HTTP status code 502.
spread.js:25 GET [BIG URL] 502 ()
However when I go to the Network tab in Chrome and view the copied link address in browser, I get a JSON response back with the data I want. I cannot find the error in CloudWatch.
Headers
Response headers
content-length: 36
content-type: application/json
date: Fri, 13 Apr 2018 06:17:06 GMT
status: 502
via: 1.1 67284fcf464f6f1529cc1e521669622c.cloudfront.net (CloudFront)
x-amz-apigw-id: FRC2oEiuDoEF_YQ=
x-amz-cf-id: O1VfzIVPySw657r6WV34EvcPMTyeT7eFUBnM3P30NXBmdjTeWHfryw==
x-amzn-requestid: 4766f279-3ee2-11e8-9e72-bdddab0f02d6
x-cache: Error from cloudfront
Request headers
:authority: wqbgu8c3ql.execute-api.eu-west-1.amazonaws.com
:method: GET
:scheme: https
accept: application/json, text/plain, */*
accept-encoding: gzip, deflate, br
accept-language: nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7
origin: [url]
referer: [url]
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
Response: {"message": "Internal server error"}
My handler.js
'use strict'
const {
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLNonNull
} = require('graphql')
const schema = require('./schema/schema');
module.exports.query = (event, context, callback) => graphql(schema, event.queryStringParameters.query)
.then(
result => callback(null, {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin" : "*"
},
body: JSON.stringify(result)
}),
err => callback(err)
)
Maybe there's something wrong in the way I return the err in the callback?