'Unable to create AWS CloudFormation stack

I am changing the Node version of my project to 14 and trying to custom deploy it to my staging environment for testing. But after changing the version to 14, I get the following error when running serverless deploy --stage <some-name>:-

Resource handler returned message: "Uploaded file must be a non-empty zip (Service: Lambda, Status Code: 400, Request ID: fcd74175-94cd-4fd9-81ec-4a27042a685e)" (RequestToken: 54f90861-af13-989c-be06-cdb17f4b5f39, HandlerErrorCode: InvalidRequest)

Here are the console logs:-

Running "serverless" from node_modules
Serverless: Deprecation warning: bin/serverless is deprecated, use bin/serverless.js instead
            More Info: https://www.serverless.com/framework/docs/deprecations/#BIN_SERVERLESS
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service get-payment-methods.zip file to S3 (102.27 MB)...
Serverless: Validating template...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
.............................................
Serverless: Stack create finished...
 
  Serverless Error ---------------------------------------
 
  Stack with id <stack-name> does not exist
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              16.13.1
     Framework Version:         1.83.3 (local)
     Plugin Version:            3.8.4
     SDK Version:               2.3.2
     Components Version:        2.34.9

I went through the solutions given in Uploaded file must be a non-empty zip (Service: AWSLambdaInternal; Status Code: 400; Error Code: InvalidParameterValueException;. I tried upgrading the serverless version. I also tried with Node versions 14.19.1 and 14.15.4. But I keep getting the same error.

This is my package.json file:-

{
  "name": "GetPaymentMethods",
  "description": "GetPaymentMethods WebService",
  "version": "0.0.1",
  "private": true,
  "dependencies": {
    "@sentry/node": "5.12.0",
    "aws-serverless-express": "3.1.3",
    "cors": "^2.8.4",
    "dotenv": "8.0.0",
    "express": "4.16.2",
    "axios": "0.18.0",
    "node": "14.19.1"
  },
  "devDependencies": {
    "mocha": "5.0.0",
    "nyc": "^15.1.0",
    "moxios": "^0.4.0",
    "serverless-domain-manager": "^2.6.0",
    "serverless-sentry": "^1.2.0",
    "sinon": "^6.1.4",
    "supertest": "3.0.0",
    "unit.js": "2.0.0",
    "serverless-newrelic-lambda-layers": "^0.1.16",
    "eslint": "6.8.0",
    "serverless": "^1.32.0",
    "serverless-offline": "^3.31.0"
  },
  "scripts": {
    "pretest": "echo 'Running eslint' && eslint .",
    "test": "nyc mocha --recursive tests"
  },
  "nyc": {
    "reporter": [
      "lcov",
      "text-summary"
    ]
  }
}

This is my serverless.yml file:-

service: get-payment-methods
    
plugins:
  # - serverless-newrelic-lambda-layers
  # - serverless-domain-manager
  # - serverless-sentry
  - serverless-offline


provider:
  name: aws
  runtime: nodejs14.x
  region: eu-west-1
  memorySize: 128
  timeout: 30
  endpointType: REGIONAL
  deploymentBucket:
    name: np-serverless-deploy-bucket-npr
  environment:
    CONFIG: ${file(./serverless.env.yml):${opt:stage}.CONFIG} 
   
functions:
  get-payment-methods:
    handler: index.handler
    events:
      - http:
          path: /
          method: get
          cors: true
      - http:
          path: /v1/test
          method: get
          cors: true
      - http:
          path: /v1
          method: get
          cors: true         

I cannot use the latest Node v16 because AWS Lambda and CodeBuild does not support it. I have to use v14. Please help.

P.S. - The global Node version in my machine is 16.13.1, if that matters.



Solution 1:[1]

So, I solved this by keeping the same NodeJS version for this project repo and the global one. It seems serverless picks up the global version for some reason and not the local one, which causes a conflict (check the console log I posted in the question). For me, v14.17.1 and v14.17.6 worked, without having to upgrade any other packages.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sh4dy