Got: Got 10 doesn't work with AWS XRay in lambda

Created on 15 Jan 2020  路  2Comments  路  Source: sindresorhus/got

Describe the bug

  • Node.js version: 10.x and 12.x
  • OS & version: AWS Lambda, Got 10

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.

Actual behavior

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.

Expected behavior

Get contents of google.com and return the specified response (body: 'ok')

Code to reproduce

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',
    }
}

Checklist

  • [x] I have read the documentation.
  • [x] I have tried my code with the latest version of Node.js and Got. (Lambda only supports up to Node.js 12)
external

Most helpful comment

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.

All 2 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joolfe picture joolfe  路  3Comments

erfanium picture erfanium  路  3Comments

khizarsonu picture khizarsonu  路  3Comments

lukechu10 picture lukechu10  路  3Comments

framerate picture framerate  路  4Comments