admin管理员组

文章数量:1129683

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

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

Share Improve this question edited Jan 8 at 15:24 Pavel asked Jan 8 at 14:54 PavelPavel 615 bronze badges 1
  • 2 Got the same problem today, but with @aws-sdk/middleware-sdk-s3/dist-cjs/index.js. Wonder if that's a coincidence. Note: Tried running the same code against AWS SAM locally and it worked perfectly fine. – Hellaren Commented Jan 8 at 19:52
Add a comment  | 

2 Answers 2

Reset to default 1

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).

After Hellaren hint I changed my package.json to

{
  "name": "cdk-typescript",
  "version": "0.1.0",
  "bin": {
    "cdk-typescript": "bin/cdk-typescript.js"
  },
  "scripts": {
    "build": "tsc",
    "watch": "tsc -w",
    "cdk": "cdk"
  },
  "devDependencies": {
    "@aws-lambda-powertools/logger": "^1.9.0",
    "@aws-lambda-powertools/metrics": "^1.8.0",
    "@middy/core": "^4.5.0",
    "@types/luxon": "^3.3.3",
    "@types/node": "22.2.0",
    "@types/uuid": "^10.0.0",
    "aws-cdk": "^2.151.0",
    "axios": "^1.6.2",
    "cron-parser": "^4.9.0",
    "cron-validator": "^1.3.1",
    "esbuild": "^0.23.0",
    "luxon": "^3.4.3",
    "p-limit": "^6.1.0",
    "sms-segments-calculator": "^1.2.0",
    "split2": "^4.2.0",
    "ts-node": "^10.9.1",
    "typescript": "^5.2.2",
    "ulid": "^2.3.0",
    "uuid": "^10.0.0"
  },
  "dependencies": {
    "@aws-sdk/client-dynamodb": "^3.701.0",
    "@aws-sdk/client-lambda": "^3.341.0",
    "@aws-sdk/client-s3": "^3.701.0",
    "@aws-sdk/client-scheduler": "^3.350.0",
    "@aws-sdk/client-secrets-manager": "^3.358.0",
    "@aws-sdk/client-sqs": "^3.701.0",
    "@aws-sdk/lib-dynamodb": "^3.701.0",
    "@aws-sdk/protocol-http": "^3.374.0",
    "@aws-sdk/s3-request-presigner": "^3.699.0",
    "@aws-sdk/util-create-request": "^3.342.0",
    "@mondia/lambda-logger": "^2.0.3",
    "@types/aws-lambda": "^8.10.143",
    "@types/split2": "^4.2.3",
    "aws-cdk-lib": "^2.151.0",
    "aws-lambda": "^1.0.7",
    "constructs": "^10.3.0",
    "source-map-support": "^0.5.16"
  }
}

and problem gone

本文标签: