DataDog / datadog-lambda-js

The Datadog AWS Lambda Library for Node
Apache License 2.0
109 stars 35 forks source link

Remove dependency on deprecated aws-sdk v2 #440

Closed glenthomas closed 9 months ago

glenthomas commented 9 months ago

Expected Behavior

The aws-sdk v2 had been deprecated in favour of AWS SDK v3. There is still a dependency on v2 here because of @types/aws-sdk. Can this code be updated to use AWS SDK v3 and then remove @types/aws-sdk from package.json?

Actual Behavior

Dependency on aws-sdk v2 exists

Steps to Reproduce the Problem

1. 1. 1.

Specifications

Stacktrace

  Paste here
astuyve commented 9 months ago

Hi @glenthomas!

Thanks for reaching out. We don't take any dependency on aws-sdk as you noted, only the types which are a dev dependency and not part of the distributed package.

There shouldn't be any additional overhead at runtime as a result of this, we're not packaging the aws-sdk in any way. Furthermore we can't drop this specific feature because the aws-sdk v2 is still the only runtime-available aws sdk for node 14 and node 16, so we won't be able to drop it entirely until both of those runtimes are deprecated.

I'll close this ticket as phase 1 deprecation for node16 is June 2024. This phase still allows existing functions to be updated so I'm not sure we'll publish something breaking at that time, we may wait until phase 2.

Please let me know if there's a specific issue that you're running into as a result of this.

Thanks!

Josefnm commented 9 months ago

I am getting runtime errors due this: require("aws-sdk/clients/kms") kms-service.ts

I deployed 3 different services and got this error 2 times for specific function each time.

"2023-11-23T13:46:43.436Z\tundefined\tERROR\tUncaught Exception \t{\"errorType\":\"Runtime.ImportModuleError\",\"errorMessage\":\"Error: Cannot find module 'aws-sdk'\nRequire stack:\n- /var/task/handler.js\n- /opt/nodejs/node_modules/datadog-lambda-js/runtime/user-function.js\n- /opt/nodejs/node_modules/datadog-lambda-js/runtime/index.js\",\"stack\":[\"Runtime.ImportModuleError: Error: Cannot find module 'aws-sdk'\",\"Require stack:\",\"- /var/task/handler.js\",\"- /opt/nodejs/node_modules/datadog-lambda-js/runtime/user-function.js\",\"- /opt/nodejs/node_modules/datadog-lambda-js/runtime/index.js\",\" at ImportModuleError.ExtendedError [as constructor] (/opt/nodejs/node_modules/datadog-lambda-js/runtime/errors.js:113:28)\",\" at new ImportModuleError (/opt/nodejs/node_modules/datadog-lambda-js/runtime/errors.js:123:42)\",\" at /opt/nodejs/node_modules/datadog-lambda-js/runtime/user-function.js:273:31\",\" at step (/opt/nodejs/node_modules/datadog-lambda-js/runtime/user-function.js:43:23)\",\" at Object.throw (/opt/nodejs/node_modules/datadog-lambda-js/runtime/user-function.js:24:53)\",\" at rejected (/opt/nodejs/node_modules/datadog-lambda-js/runtime/user-function.js:16:65)\"]}"

astuyve commented 9 months ago

Hi @Josefnm - The kms-service module doesn't appear in that call stack, so I don't think it's causing this issue.

My guess is that your function depends on the aws-sdk v2, but you've deployed your function code to Node18 or Node20 runtimes, which only include the aws-sdk v3.

The top of this trace is from user-function.js, which is the file we use to load your handler.

To fix this, you'll probably want to update your code to use aws-sdk v3.

Thanks!

Josefnm commented 9 months ago

Thank you. As I had checked all my dependencies and yours was the only that still contained any reference to the v2 aws-sdk, I made a false assumption. It stopped happening after cleaning everything up so maybe something old had snuck into my build process ¯_(ツ)_/¯