Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke local fails with docker if app and org are set #6939

Open
petewalker opened this issue Nov 7, 2019 · 7 comments
Open

Invoke local fails with docker if app and org are set #6939

petewalker opened this issue Nov 7, 2019 · 7 comments

Comments

@petewalker
Copy link

petewalker commented Nov 7, 2019

Bug Report

Description

serverless invoke local -f hello --docker fails if app and org are set in serverless.yml

What did you do?

  1. Set up a template serverless project in nodejs10.x, and when prompted, connect to a serverless project.
  2. Run serverless invoke local -f hello --docker

What happened?

An error is thrown: TypeError: e is not a function.

This is failing because wrapNodeJS is being called twice during the invocation. This is because it's associated with 2 hooks which both fire when app and org are set.

This means that the resultant s_hello.js file ends up referencing itself:

try {
  const userHandler = require('./s_hello.js')
  module.exports.handler = serverlessSDK.handler(userHandler.handler, handlerWrapperArgs)
} catch (error) {
  module.exports.handler = serverlessSDK.handler(() => { throw error }, handlerWrapperArgs)
}

The e is not a function refers to the handler function not being a valid function any more.

What should've happened?

The lambda function runs.

What's the content of your serverless.yml file?

service: test-case
# app and org for use with dashboard.serverless.com
app: test-case
org: myorg

provider:
  name: aws
  runtime: nodejs10.x

functions:
  hello:
    handler: handler.hello

What's the output you get when you use the SLS_DEBUG=* environment variable (e.g. SLS_DEBUG=* serverless deploy)

Serverless: Load command interactiveCli
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command config:tabcompletion
Serverless: Load command config:tabcompletion:install
Serverless: Load command config:tabcompletion:uninstall
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command generate-event
Serverless: Load command test
Serverless: Load command dashboard
platform-sdk fetching: POST https://api.serverless.com/core/tenants/myorg/applications/test-case/profileValue
Serverless: Invoke invoke:local
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:common:cleanupTempDir
platform-sdk fetching: GET https://api.serverless.com/core/tenants/myorg/applications/test-case
platform-sdk fetching: GET https://api.serverless.com/core/meta
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Invoke aws:package:finalize
Serverless: [AWS sts 200 0.502s 0 retries] getCallerIdentity({})
platform-sdk fetching: POST https://api.serverless.com/malt/destinations/create
Serverless: Invoke aws:common:moveArtifactsToPackage
Serverless: Building Docker image...
START RequestId: 70167470-2e13-10a4-bee0-021c424953c5 Version: $LATEST

2019-11-07T20:11:44.707Z	70167470-2e13-10a4-bee0-021c424953c5	INFO	

    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25):9:88355)c5	ERROR	TypeError: e is not a function

2019-11-07T20:11:44.736Z	70167470-2e13-10a4-bee0-021c424953c5	INFO	SERVERLESS_ENTERPRISE {"origin":"sls-agent","schemaVersion":"0.0","timestamp":"2019-11-07T20:11:44.736Z","requestId":"70167470-2e13-10a4-bee0-021c424953c5","type":"error","payload":{"schemaType":"s-span","schemaVersion":"0.0","operationName":"s-transaction-function","startTime":"2019-11-07T20:11:44.699Z","endTime":"2019-11-07T20:11:44.736Z","duration":36.7172,"spanContext":{"traceId":"70167470-2e13-10a4-bee0-021c424953c5","spanId":"fe97477b-1351-471a-86c8-e8adc6e6df8e","xTraceId":"Parent=11560be54abce8ed"},"tags":{"schemaType":"s-transaction-function","schemaVersion":"0.0","timestamp":"2019-11-07T20:11:44.699Z","tenantId":"myorg","applicationName":"test-case","serviceName":"test-cas","stageName":"dev","functionName":"test-cas-dev-hello","timeout":6,"computeType":"aws.lambda","computeRuntime":"aws.lambda.nodejs.10.17.0","computeRegion":"us-east-1","computeMemorySize":"1536","computeMemoryUsed":"{\"rss\":45576192,\"heapTotal\":18636800,\"heapUsed\":10339912,\"external\":387080}","computeMemoryPercentageUsed":0.6510416666666667,"computeContainerUptime":0.173,"computeIsColdStart":true,"computeInstanceInvocationCount":1,"computeCustomSchemaType":"s-compute-aws-lambda","computeCustomSchemaVersion":"0.0","computeCustomFunctionName":"test","computeCustomFunctionVersion":"$LATEST","computeCustomArn":"arn:aws:lambda:us-east-1:934483123:function:test","computeCustomRegion":"us-east-1","computeCustomMemorySize":"1536","computeCustomInvokeId":null,"computeCustomAwsRequestId":"70167470-2e13-10a4-bee0-021c424953c5","computeCustomXTraceId":"Parent=11560be54abce8ed","computeCustomLogGroupName":"/aws/lambda/test","computeCustomLogStreamName":"2019/11/07/[$LATEST]437854f312fdc91a972ce0cc1132f31c","computeCustomEnvPlatform":"linux","computeCustomEnvArch":"x64","computeCustomEnvMemoryTotal":6246551552,"computeCustomEnvMemoryFree":4789116928,"computeCustomEnvCpus":"[{\"model\":\"Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz\",\"speed\":2600,\"times\":{\"user\":123400,\"nice\":0,\"sys\":222000,\"idle\":161369100,\"irq\":0}},{\"model\":\"Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz\",\"speed\":2600,\"times\":{\"user\":140400,\"nice\":0,\"sys\":174400,\"idle\":161168000,\"irq\":0}},{\"model\":\"Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz\",\"speed\":2600,\"times\":{\"user\":168000,\"nice\":0,\"sys\":198300,\"idle\":161380900,\"irq\":0}},{\"model\":\"Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz\",\"speed\":2600,\"times\":{\"user\":139200,\"nice\":0,\"sys\":192700,\"idle\":161301000,\"irq\":0}},{\"model\":\"Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz\",\"speed\":2600,\"times\":{\"user\":141200,\"nice\":0,\"sys\":166200,\"idle\":161520000,\"irq\":0}},{\"model\":\"Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz\",\"speed\":2600,\"times\":{\"user\":152200,\"nice\":0,\"sys\":176100,\"idle\":161500200,\"irq\":0}}]","eventType":"unknown","eventTimestamp":"2019-11-07T20:11:44.700Z","eventSource":null,"eventCustomStage":"dev","errorId":"TypeError!$e is not a function","errorFatal":true,"errorCulprit":"Runtime.handler (serverless_sdk/index.js)","errorExceptionType":"TypeError","errorExceptionMessage":"e is not a function","errorExceptionStacktrace":"[{\"filename\":\"serverless_sdk/index.js\",\"lineno\":9,\"function\":\"Runtime.handler\",\"library_frame\":false,\"abs_path\":\"/var/task/serverless_sdk/index.js\",\"pre_context\":[\" * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>\",\" * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors\"],\"context_line\":\" */(function(){var o,i=200,u=\\\"Unsupported core-js use. Try https://npms.io/search?q=ponyfill.\\\",s=\\\"Ex\",\"post_context\":[\"/*!\",\" * Determine if an object is a Buffer\"]},{\"filename\":\"/var/runtime/Runtime.js\",\"lineno\":66,\"function\":\"handleOnce\",\"library_frame\":false,\"abs_path\":\"/var/runtime/Runtime.js\",\"pre_context\":[\"      this._setDefaultExitListener(invokeContext.invokeId);\",\"\"],\"context_line\":\"      let result = this.handler(\",\"post_context\":[\"        JSON.parse(bodyJson),\",\"        invokeContext.attachEnvironmentData(callbackContext),\"]}]","transactionId":"fe97477b-1351-471a-86c8-e8adc6e6df8e","appUid":"CdDK4YHqv6LlyZqkCl","tenantUid":"R9bPMgVK5G9w4vygn3","pluginVersion":"3.2.2","totalSpans":0,"traceId":"70167470-2e13-10a4-bee0-021c424953c5"},"logs":{},"spans":[],"eventTags":[]}}

2019-11-07T20:11:44.737Z	70167470-2e13-10a4-bee0-021c424953c5	ERROR	Invoke Error	{"errorType":"TypeError","errorMessage":"e is not a function","stack":["TypeError: e is not a function","    at Runtime.handler (/var/task/serverless_sdk/index.js:9:88355)","    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"]}

END RequestId: 70167470-2e13-10a4-bee0-021c424953c5
REPORT RequestId: 70167470-2e13-10a4-bee0-021c424953c5	Duration: 48.16 ms	Billed Duration: 100 ms	Memory Size: 1536 MB	Max Memory Used: 50 MB	
{
  "errorType": "TypeError",
  "errorMessage": "e is not a function"
}

 
 Exception -----------------------------------------------
 
  1
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              10.16.0
     Framework Version:         1.57.0
     Plugin Version:            3.2.2
     SDK Version:               2.2.1
     Components Core Version:   1.1.2
     Components CLI Version:    1.4.0
@jonathon-m
Copy link

This is still an issue in 1.64.0.

@fyaconiello
Copy link

this is still an issue in 1.76.1

@medikoo
Copy link
Contributor

medikoo commented Dec 3, 2021

Is this an issue with the latest Framework version?

@danielolaviobr
Copy link

Still an issue at

Framework Core: 2.72.2
Plugin: 5.5.4
SDK: 4.3.0
Components: 3.18.2

@medikoo
Copy link
Contributor

medikoo commented Feb 2, 2022

@danielolaviobr How about latest v3 release?

@danielolaviobr
Copy link

@danielolaviobr How about latest v3 release?

Haven't tested

@fro-dev-clau
Copy link

I have a similar issue

when I run this config it works

service: rbk-web

provider:
  name: aws
  runtime: nodejs14.x
  stage: dev
  region: us-east-1

functions:
  nuxt:
    handler: .output/server/index.handler
    events:
      - httpApi: '*'

with this it fails

org: franciscoramoso
app: rbk-web
service: rbk-web

provider:
  name: aws
  runtime: nodejs14.x
  stage: dev
  region: us-east-1

functions:
  nuxt:
    handler: .output/server/index.handler
    events:
      - httpApi: '*'

the s_nuxt.js file generated


var serverlessSDK = require('./serverless_sdk/index.js');
serverlessSDK = new serverlessSDK({
  orgId: 'franciscoramoso',
  applicationName: 'rbk-web',
  serviceName: 'rbk-web',
  shouldLogMeta: true,
  shouldCompressLogs: true,
  disableAwsSpans: false,
  disableHttpSpans: false,
  stageName: 'dev',
  serverlessPlatformStage: 'prod',
  devModeEnabled: false,
  accessKey: null,
  pluginVersion: '6.2.2',
  disableFrameworksInstrumentation: false
});

const handlerWrapperArgs = { functionName: 'rbk-web-dev-nuxt', timeout: 6 };

try {
  const userHandler = require('./.output/server/index.js');
  module.exports.handler = serverlessSDK.handler(userHandler.handler, handlerWrapperArgs);
} catch (error) {
  module.exports.handler = serverlessSDK.handler(() => { throw error }, handlerWrapperArgs);
}

It fails because the handler: .output/server/index is .mjs -> .output/server/index.mjs
on the generated file it tries to require it as ./.output/server/index.js

I think just require the file without adding the extension should work but Idk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants