79371679

Date: 2025-01-20 14:51:00
Score: 0.5
Natty:
Report link

I am trying to update my Node.js from version 16.x to 18.x, but I am encountering the following issue

Our serverless offline start --host 0.0.0.0 command is running perfectly, but when we try to hit the API with Postman, it shows a 502 Bad Gateway error. Here is the error displayed in our Cloud9 terminal:

GET /getVessels (λ: getVessels)

Warning: Warning: found unsupported runtime 'nodejs18.x' for function 'getVessels'
× Unsupported runtime
× Error: Unsupported runtime
      at #loadRunner (file:///home/ec2-user/CS-Dev/node_modules/serverless-offline/src/lambda/handler-runner/HandlerRunner.js:107:11)
      at HandlerRunner.run (file:///home/ec2-user/CS-Dev/node_modules/serverless-offline/src/lambda/handler-runner/HandlerRunner.js:123:44)
      at LambdaFunction.runHandler (file:///home/ec2-user/CS-Dev/node_modules/serverless-offline/src/lambda/LambdaFunction.js:313:27)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async file:///home/ec2-user/CS-Dev/node_modules/serverless-offline/src/events/http/HttpServer.js:566:18
      at async exports.Manager.execute (/home/ec2-user/CS-Dev/node_modules/@hapi/hapi/lib/toolkit.js:60:28)
      at async internals.handler (/home/ec2-user/CS-Dev/node_modules/@hapi/hapi/lib/handler.js:46:20)
      at async exports.execute (/home/ec2-user/CS-Dev/node_modules/@hapi/hapi/lib/handler.js:31:20)
      at async Request._lifecycle (/home/ec2-user/CS-Dev/node_modules/@hapi/hapi/lib/request.js:371:32)
      at async Request._execute (/home/ec2-user/CS-Dev/node_modules/@hapi/hapi/lib/request.js:281:9)

our package.json

{ 
"name": "cs-db",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "sls offline start",
    "test": "jest"
  },
  "author": "test",
  "license": "ISC",
  "dependencies": {
    "@aws-sdk/client-cognito-identity-provider": "^3.731.1",
    "@aws-sdk/client-dynamodb": "^3.731.1",
    "@aws-sdk/client-lambda": "^3.731.1",
    "@aws-sdk/client-s3": "^3.731.1",
    "@aws-sdk/client-secrets-manager": "^3.731.1",
    "@aws-sdk/cloudfront-signer": "^3.723.0",
    "@aws-sdk/lib-dynamodb": "^3.731.1",
    "amazon-cognito-identity-js": "^6.3.3",
    "aws-lambda": "^1.0.7",
    "axios": "^1.2.2",
    "crypto": "^1.0.1",
    "encoding": "^0.1.13",
    "generate-unique-id": "^2.0.3",
    "iconv-lite": "^0.6.3",
    "install": "^0.13.0",
    "joi": "^17.9.2",
    "jschardet": "^3.0.0",
    "jsonwebtoken": "^9.0.1",
    "jwk-to-pem": "^2.0.5",
    "mongodb": "^5.9.2",
    "mysql2": "^3.10.1",
    "npm": "^10.4.0",
    "papaparse": "^5.4.1",
    "pdf-lib": "^1.17.1",
    "serverless-plugin-typescript": "^2.1.5",
    "uuid": "^8.3.2",
    "wildcard": "^2.0.1",
    "xlsx": "^0.18.5"
  },
  "devDependencies": {
    "@types/jest": "^29.5.1",
    "jest": "^29.5.0",
    "serverless-offline": "^9.3.1",
    "ts-jest": "^29.1.0",
    "typescript": "^4.7.4"
  },
  "jest": {
    "preset": "ts-jest"
  }
}

and our serverless.yml

service: Feature-dev
# frameworkVersion: '3'

provider:
  name: aws
  runtime: nodejs18.x
  versionFunctions: false
  stage: v3
  region: eu-east-1
  vpc:
    securityGroupIds:
      - sg-12121
    subnetIds:
      - subnet-123211
  environment:
#    IS_OFFLINE: ${opt:offline, 'true'}
  iamRoleStatements:
    - Effect: Allow
      Action:
        - secretsmanager:GetSecretValue
        - s3:test
        - s3:test
        - s3:test
        - ec2:*
        - docdb:*
        - cognito-idp:test
        - dynamodb:GetItem
        - states:StartExecution
      Resource: "*"
package:
  patterns:
    - src/**               # include only files from ./src/**/*
    - node_modules/**      # include files from ./node_modules/**/*
    - '!node_modules/aws-sdk/**'  # exclude AWS SDK as it is included in the Lambda runtime
  getVessels:
    handler: src/getVessels.getVessels
    events: 
      - http:
          path: /getVessels
          method: get
          cors: true
Reasons:
  • Blacklisted phrase (1): I am trying to
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Chandan Kumar