This might not be caused by Got, but occurs when using Got 10 in combination with AWS XRay on AWS Lambda. Note: Got 9 works fine with the provided snippet.
I also opened an issue on the aws-xray-sdk-node repository.
Whenever XRay capture is enabled, the lambda doesn't return any response, and the actual request is made against https://localhost. Subsequent executions take longer and longer (even up to 2 minutes) until finally one execution will show a bunch of LAMBDA_RUNTIME_ERROR.
Get contents of google.com and return the specified response (body: 'ok')
require('aws-xray-sdk-core').captureHTTPsGlobal(require('https'))
const got = require('got')
export async function handler() {
await got.get(`https://google.com`)
return {
statusCode: 200,
body: 'ok',
}
}
aws-xray-sdk-core monkey-patches the https module wrongly. They provide only request(options, callback) while we use Node 10's request(url, options, callback). Closing since this is not a Got issue.
Thanks! I quickly verified, and indeed if I monkey-patch the aws-xrat-sdk-core code right before deploying it to lambda to only provide the request(url, options, callback) (just to verify, not a desired solution), the Got request succeeds as expected! I'll update the issue on their side to include this info. Thanks again!
Most helpful comment
aws-xray-sdk-coremonkey-patches thehttpsmodule wrongly. They provide onlyrequest(options, callback)while we use Node 10'srequest(url, options, callback). Closing since this is not a Got issue.