Open ilanc opened 4 years ago
@ilanc can you prepare a clean reproduction test case, that doesn't involve a Webpack? It might that issue is in your webpack configuration and that's out of scope of this project.
howdy - the problem is the UserFunction.js code inside the serverless framework. I just logged on to try and get the callstack from the dashboard.serverless.com but it's hidden (as of 10 mins ago? with a message about upgrading serverless enterprise plugin?).
It looked like the sls framework injects it's own handler which then needs to find and require your handler and run it. I'm pretty sure that's where the problem is. If UserFunction.js see a handler with dotted notation then it need to strip out the parts and look for files in /tmp
until it finds a match
i.e. for handler.main.post
it should look for:
main.post()
=> this is what I need (and what sls vanilla / lambda framwork appears to already do)post()
default()
i guess? @ilanc for general support please use https://forum.serverless.com/ or https://www.serverless.com/slack
This issue tracker is purely for bug reports or feature requests, and those should be reported with full respect to template remarks (e.g. no webpack, external plugins etc. involved)
Hi @medikoo, this is a valid bug report. The serverless framework has different behaviour to the vanilla sls - behaviour that will prevent non-default export handler.js functions from being called AFAICT - i.e. a bug.
Ignore the comments about the dashboard I just mentioned this because I was going to send you the stack trace from the dashboard which would have made it obvious where the bug lies.
I'm well acquainted with the various serverless offerings as well as the forum, this is the correct place for this bug report.
Hi @medikoo, this is a valid bug report. The serverless framework has different behaviour to the vanilla sls - behaviour that will prevent non-default export handler.js functions from being called AFAICT - i.e. a bug.
@ilanc can you prove it with reproducible test case that doesn't involve webpack?
sure
Here you go: https://github.com/ilanc/bug-demo
@medikoo you'll need to follow the instructions in the readme to reproduce + edit the framework tenant settings for your account.
Thank you @ilanc
It appears that dashboard plugin doesn't handle nested handler references properly
/cc @astuyve @scouredimage
:+1:
Hi @medikoo - I see that I am assigned to this. Are you awaiting a pull request from me? or am I supposed to comment on the linked PR from @astuyve?
Hi @medikoo - I see that I am assigned to this. Are you awaiting a pull request from me?
@ilanc I've assigned you initially as post was not clear to me. I've removed the assignment.
Still if you know how to fix it, PR is definitely welcome
or am I supposed to comment on the linked PR from @astuyve?
Which PR you mean?
Thanks @medikoo. Ignore my comment about the PR - I saw that there was "1 PR" in the tabs at the top of the page and assumed that it was linked. But it's actually just a list of all currently active PRs.
I'm unable to invoke an httpApi lambda when I deploy it using
sls framework
. However if I simply comment out the framework config ({org, app}
) in theserverless.yml
and re-deploy (i.e. using vanillasls
), then I am able to invoke the lambda successfully.For the broken
sls framework
version I see this in the logs:Problem cause:
handler.js
nothandler.main.js
sls
handles dotted notation in the function handler name differently to thesls framework
versionBackground info:
exports["main"] = ...
).handler: handler.main.post
(where post is the name of a function which I export)
```yaml service: lambda-pdf # org: ilanc # app: lambda-pdf provider: name: aws runtime: nodejs12.x region: eu-west-2 stage: prod deploymentBucket: name: spike-serverless-deploy functions: convert: description: lambda version of @spike/pdf memorySize: 512 timeout: 5 handler: handler.main.post # can't use `export default` from webpacked .ts files events: - httpApi: method: POST path: / ```serverless.yml
``` 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 upgrade Serverless: Load command uninstall Serverless: Load command login Serverless: Load command logout Serverless: Load command generate-event Serverless: Load command test Serverless: Load command dashboard Serverless: Load command output Serverless: Load command output:get Serverless: Load command output:list Serverless: Load command param Serverless: Load command param:get Serverless: Load command param:list Serverless: Load command studio Serverless: Load command dev platform-sdk fetching: POST https://api.serverless.com/core/tenants/ilanc/applications/lambda-pdf/profileValue Serverless: Invoke deploy Serverless: Invoke package Serverless: Invoke aws:common:validate Serverless: Invoke aws:common:cleanupTempDir platform-sdk fetching: GET https://api.serverless.com/core/tenants/ilanc/applications/lambda-pdf 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 1.6s 0 retries] getCallerIdentity({}) platform-sdk fetching: POST https://api.serverless.com/malt/destinations/create Serverless: Invoke aws:common:moveArtifactsToPackage Serverless: Invoke aws:common:validate Serverless: [AWS s3 200 1.178s 0 retries] getBucketLocation({ Bucket: 'spike-serverless-deploy' }) Serverless: Safeguards Processing... Serverless: Safeguards Results: Summary -------------------------------------------------- passed - no-secret-env-vars passed - no-unsafe-wildcard-iam-permissions passed - framework-version passed - allowed-stages passed - allowed-regions passed - allowed-runtimes Serverless: Safeguards Summary: 6 passed, 0 warnings, 0 errors Serverless: Invoke aws:deploy:deploy Serverless: [AWS cloudformation 200 1.339s 0 retries] describeStacks({ StackName: 'lambda-pdf-prod' }) Serverless: [AWS s3 200 0.653s 0 retries] listObjectsV2({ Bucket: 'spike-serverless-deploy', Prefix: 'serverless/lambda-pdf/prod' }) Serverless: [AWS s3 200 0.627s 0 retries] headObject({ Bucket: 'spike-serverless-deploy', Key: 'serverless/lambda-pdf/prod/1592825346115-2020-06-22T11:29:06.115Z/compiled-cloudformation-template.json' }) Serverless: [AWS s3 200 0.636s 0 retries] headObject({ Bucket: 'spike-serverless-deploy', Key: 'serverless/lambda-pdf/prod/1592825346115-2020-06-22T11:29:06.115Z/lambda-pdf.zip' }) Serverless: [AWS lambda 200 0.755s 0 retries] getFunction({ FunctionName: 'lambda-pdf-prod-convert' }) Serverless: [AWS sts 200 1.205s 0 retries] getCallerIdentity({}) Serverless: Uploading CloudFormation file to S3... Serverless: [AWS s3 200 0.799s 0 retries] putObject({ Body:sls deploy (framework version)
output
``` 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 upgrade Serverless: Load command uninstall Serverless: Load command login Serverless: Load command logout Serverless: Load command generate-event Serverless: Load command test Serverless: Load command dashboard Serverless: Load command output Serverless: Load command output:get Serverless: Load command output:list Serverless: Load command param Serverless: Load command param:get Serverless: Load command param:list Serverless: Load command studio Serverless: Load command dev Serverless: Invoke deploy Serverless: Invoke package Serverless: Invoke aws:common:validate Serverless: Invoke aws:common:cleanupTempDir Serverless: Packaging service... Serverless: Excluding development dependencies... Serverless: Invoke aws:package:finalize Serverless: Invoke aws:common:moveArtifactsToPackage Serverless: Invoke aws:common:validate Serverless: [AWS s3 200 0.982s 0 retries] getBucketLocation({ Bucket: 'spike-serverless-deploy' }) Serverless: Invoke aws:deploy:deploy Serverless: [AWS cloudformation 200 1.245s 0 retries] describeStacks({ StackName: 'lambda-pdf-prod' }) Serverless: [AWS s3 200 0.725s 0 retries] listObjectsV2({ Bucket: 'spike-serverless-deploy', Prefix: 'serverless/lambda-pdf/prod' }) Serverless: [AWS s3 200 0.615s 0 retries] headObject({ Bucket: 'spike-serverless-deploy', Key: 'serverless/lambda-pdf/prod/1592823993487-2020-06-22T11:06:33.487Z/compiled-cloudformation-template.json' }) Serverless: [AWS s3 200 0.624s 0 retries] headObject({ Bucket: 'spike-serverless-deploy', Key: 'serverless/lambda-pdf/prod/1592823993487-2020-06-22T11:06:33.487Z/lambda-pdf.zip' }) Serverless: [AWS lambda 200 0.736s 0 retries] getFunction({ FunctionName: 'lambda-pdf-prod-convert' }) Serverless: [AWS sts 200 1.658s 0 retries] getCallerIdentity({}) Serverless: Uploading CloudFormation file to S3... Serverless: [AWS s3 200 0.757s 0 retries] putObject({ Body:sls deploy (vanilla version)
outputInstalled version
Additional:
```js const path = require("path"); const webpack = require("webpack"); const functionSrcFile = "handler"; module.exports = { target: "node", // mode: "production", mode: "development", optimization: { usedExports: true, }, entry: { [functionSrcFile]: ["./build/main/" + functionSrcFile], // will create ../dist/{functionSrcFile}.js }, output: { path: path.join(__dirname, "dist"), filename: "[name].js", libraryTarget: "commonjs", library: "main", }, module: { rules: [ { test: /\.js?$/, exclude: /node_modules/, loader: "babel-loader", options: { presets: [ [ "@babel/env", { targets: { node: "12", }, }, ], ], }, }, ], }, resolve: { extensions: [".mjs", ".js"], }, externals: ["aws-sdk"], // aws-sdk included in lambda - no need to bundle it };webpack.config.js