Search code examples
node.jstypescriptaws-lambda

"errorType": "TypeError" "errorMessage": "Object.defineProperty called on non-object"


I use AWS lambdas + typeScript

when i make a request to lambda via Api Gateway

I have response 502 Bad Gateway

{
    "message": "Internal server error"
}

and error in lambda

{
    "errorType": "TypeError",
    "errorMessage": "Object.defineProperty called on non-object",
    "stack": [
        "TypeError: Object.defineProperty called on non-object",
        "    at defineProperty (<anonymous>)",
        "    at __name (/var/task/index.js:24690:37)",
        "    at <static_initializer> (/var/task/index.js:24816:9)",
        "    at node_modules/@aws-sdk/lib-dynamodb/dist-cjs/index.js (/var/task/index.js:24814:82)",
        "    at __require (/var/task/index.js:10:50)",
        "    at Object.<anonymous> (/var/task/index.js:44040:35)",
        "    at Module._compile (node:internal/modules/cjs/loader:1364:14)",
        "    at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)",
        "    at Module.load (node:internal/modules/cjs/loader:1203:32)",
        "    at Module._load (node:internal/modules/cjs/loader:1019:12)"
    ]
}

but just few days ago everything was fine and nothing changed what can be the problem

for run lambda I use NODEJS_18

"dependencies": {
    "@aws-cdk/aws-iam": "^1.202.0",
    "@aws-cdk/aws-lambda-event-sources": "^1.202.0",
    "@aws-sdk/client-dynamodb": "^3.637.0",
    "@aws-sdk/client-lambda": "^3.698.0",
    "@aws-sdk/client-s3": "^3.698.0",
    "@aws-sdk/client-scheduler": "^3.350.0",
    "@aws-sdk/client-secrets-manager": "^3.358.0",
    "@aws-sdk/client-sqs": "^3.637.0",
    "@aws-sdk/lib-dynamodb": "^3.637.0",
    "@aws-sdk/protocol-http": "^3.374.0",
    "@aws-sdk/s3-request-presigner": "^3.699.0",
    "@aws-sdk/util-create-request": "^3.699.0",
    "@types/aws-lambda": "^8.10.96",
    "@types/split2": "^4.2.3",
    "aws-cdk-lib": "^2.76.0",
    "aws-lambda": "^1.0.7",
    "constructs": "^10.0.0",
    "source-map-support": "^0.5.16"
  }

If you need more details please ask


Solution

  • Not sure what exactly is broken in the latest version of the @aws-sdk, but if you pin the version of the package to the older one that worked for you, this should solve the issue

    In your package.json set the version of the client-s3 and client-dynamodb to

      "dependencies": {
        "@aws-sdk/client-s3": "3.701.0",
        "@aws-sdk/client-dynamodb": "3.701.0",
        ...
      },
    

    Don't forget to run:

    npm install
    

    It would probably make sense to create an issue in AWS SDK Github repo to ensure they are aware of the problem (if it doesn't exist yet).