dherault / serverless-offline

Emulate AWS λ and API Gateway locally when developing your Serverless project
MIT License
5.2k stars 793 forks source link

Cannot read properties of undefined (reading 'notice') when downloading layer, #1303

Closed feline-dis closed 2 years ago

feline-dis commented 2 years ago

Hello! I have the following serverless.yml file and am running into some issues when trying to use the --useDocker option.

service: opportunity
package:
  include:
    - src/**
  exclude:
    - buildspec.yml
    - tests/**
    - README.md
plugins:
  - serverless-offline
custom:
  serverless-offline:
    useDocker: true
provider:
  name: aws
  runtime: nodejs12.x
  stage: ${opt:stage, env:PASSING_STAGE} # Use the command line option or if not provided use the PASSING_STAGE env var to populate the stage
  region: us-east-2
  timeout: 29 # API Gateway timeout for integrations is 29 seconds
  memorySize: 1024 # Default is 1024
  versionFunctions: false # optional, default is true
  role: arn:aws:iam::::***********::role/lambda-cloudwatchlogs-vpc-sns-kms-secrets-write # Set the default role for all Lambda functions in this service
  environment:
    stage: ${opt:stage, env:PASSING_STAGE}

functions:
  getOpportunity:
    handler: src/handlers/opportunity/getOpportunity.handler
    layers:
      # - arn:aws:lambda:us-east-2:::***********::layer:opportunity-model-layer:25
      # - arn:aws:lambda:us-east-2:::***********::layer:common-model-layer:12
      - arn:aws:lambda:us-east-2:::***********::layer:lambda-layer-lib:21
    name: ${self:service}-get-opportunity-${self:provider.stage}
    description: 'Get an opportunity'
    role: arn:aws:iam::***********:role/lambda-cloudwatchlogs-vpc-sns-kms-secrets-lambda-write
    events:
      - http:
          path: get-opportunity
          method: post
          cors: true
          authorizer:
            arn: arn:aws:cognito-idp:us-east-2:262340536653:userpool/us-east-2_xVs4CmmEC

I am able make a request and start the function, however I receive the following errors:

offline: POST /beta/get-opportunity (λ: getOpportunity)
offline: Found layers, checking provider type
offline: Storing layers at D:\dev\nerd-power\microservices\v2\opportunity-microservice\.serverless-offline\layers\612fb549b4cadd19bf5edcf1f57eb598ff52970d32f1a477024c1eb9a527ecdc
offline: Getting layers
offline: [lambda-layer-lib:21] ARN: arn:aws:lambda:us-east-2:**********:layer:lambda-layer-lib:21
offline: [lambda-layer-lib:21] Getting Info
offline: Failure: Cannot read properties of undefined (reading 'notice')

TypeError: Cannot read properties of undefined (reading 'notice')
    at DockerContainer._downloadLayer (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\serverless-offline\dist\lambda\handler-runner\docker-runner\DockerContainer.js:335:19)
    at DockerContainer.start (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\serverless-offline\dist\lambda\handler-runner\docker-runner\DockerContainer.js:225:30)
    at async DockerRunner.run (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\serverless-offline\dist\lambda\handler-runner\docker-runner\DockerRunner.js:66:7)
    at async LambdaFunction.runHandler (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\serverless-offline\dist\lambda\LambdaFunction.js:368:20)
    at async hapiHandler (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\serverless-offline\dist\events\http\HttpServer.js:702:18)
    at async exports.Manager.execute (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\@hapi\hapi\lib\toolkit.js:60:28)
    at async Object.internals.handler (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\@hapi\hapi\lib\handler.js:46:20)
    at async exports.execute (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\@hapi\hapi\lib\handler.js:31:20)
    at async Request._lifecycle (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\@hapi\hapi\lib\request.js:371:32)
    at async Request._execute (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\@hapi\hapi\lib\request.js:281:9)

Any help/info would be much appreciated, I'm not sure how else to pass the layers to the function. Ive tried passing them at the provider level however it doesn't seem to recognize the layers at all when I try that approach.

Serverless Version: Framework Core: 2.66.2 (local) Plugin: 5.5.1 SDK: 4.3.0 Components: 3.18.1

serverless-offline Version: "^8.3.0"

medikoo commented 2 years ago

@JonathanHansen98 stack trace shows that you do not run the latest version of serverless-offline, please upgrade

feline-dis commented 2 years ago

@medikoo where do you see this? I just confirmed the version in my package.json is at 8.3.0 which seems to be the latest version according to the documentation. I tried deleting my package-lock.json and node_modules and running npm i just in case, but I'm still running into the same issues.

medikoo commented 2 years ago

@JonathanHansen98 top line from stack trace, doesn't match latest version. It's:

at DockerContainer._downloadLayer (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\serverless-offline\dist\lambda\handler-runner\docker-runner\DockerContainer.js:335:19)

While when you inspect latest version (at e.g. https://npmview.vercel.app/serverless-offline) you'll there's no property access at L335 of DockerContainer.js

feline-dis commented 2 years ago

Ohhh my gosh, thats totally my bad. I added some logs while at my wits end last night that messed with the line numbers causing a little misalignment there, sorry.

This is the stack trace after a clean install of the package with none of my logs to mess it up:

offline: Failure: Cannot read properties of undefined (reading 'notice')
TypeError: Cannot read properties of undefined (reading 'notice')
    at DockerContainer._downloadLayer (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\serverless-offline\dist\lambda\handler-runner\docker-runner\DockerContainer.js:332:19)
    at DockerContainer.start (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\serverless-offline\dist\lambda\handler-runner\docker-runner\DockerContainer.js:225:30)
    at async DockerRunner.run (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\serverless-offline\dist\lambda\handler-runner\docker-runner\DockerRunner.js:66:7)
    at async LambdaFunction.runHandler (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\serverless-offline\dist\lambda\LambdaFunction.js:368:20)
    at async hapiHandler (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\serverless-offline\dist\events\http\HttpServer.js:702:18)
    at async exports.Manager.execute (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\@hapi\hapi\lib\toolkit.js:60:28)
    at async Object.internals.handler (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\@hapi\hapi\lib\handler.js:46:20)
    at async exports.execute (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\@hapi\hapi\lib\handler.js:31:20)      
    at async Request._lifecycle (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\@hapi\hapi\lib\request.js:371:32)  
    at async Request._execute (D:\dev\nerd-power\microservices\v2\opportunity-microservice\node_modules\@hapi\hapi\lib\request.js:281:9)

The real line in question is L332 of DockerContainer.js, it seems like its having an issue initiating the layerProgress variable.

Once, again sorry for the confusion there 😅

medikoo commented 2 years ago

@JonathanHansen98 thanks for pointing, indeed there's a clear bug there, fix is coming