Jan Plaček
03/01/2022, 8:53 AM"GET /dist": {
function: {
bundle: false,
srcPath: "../../dist/apps/lambda/",
handler: "index.handler",
},
authorizationType: sst.ApiAuthorizationType.NONE,
}
results in
127e794d-009b-4136-b06e-dda7d1f2c97a REQUEST jplacek-sst-my-stack-ApiLambdaGETdist77255DFF-QTX6rp9SQ4te [index.handler] invoked by API GET /dist
X [ERROR] Cannot use "external" without "bundle"
127e794d-009b-4136-b06e-dda7d1f2c97a ERROR build_failure: The function index.handler failed to build
manitej
03/01/2022, 8:55 AMJan Plaček
03/01/2022, 9:00 AMdist
dir with lambda is outside of sst project directory, is that the issue?Jan Plaček
03/01/2022, 9:04 AMJan Plaček
03/01/2022, 9:09 AMnx
monorepo:
root/
root/apps/sst (sst project)
root/apps/web (angular project)
root/apps/lambda (nestjs project)
root/dist/apps/lambda (builded nestjs project)
Jan Plaček
03/01/2022, 10:04 AM"GET /dist": {
function: {
// ERROR: Cannot use "external" without "bundle"
bundle: false,
srcPath: "dist/apps/lambda/",
handler: "index.handler",
},
authorizationType: sst.ApiAuthorizationType.NONE,
}
Jan Plaček
03/01/2022, 10:05 AMFrank
Jan Plaček
03/01/2022, 10:47 AMJan Plaček
03/01/2022, 10:47 AMFrank
sst start
right?Frank
sst.json
is at the root, it should.Jan Plaček
03/01/2022, 10:51 AMesbuild
due to some incompatibilities with nestjs
. So the idea is to setup watcher on my nestjs
project use own build process, and then the sst should pickup the changes and reload lambda with new build.Frank
"GET /dist": {
function: {
bundle: false,
srcPath: "dist/apps/lambda/",
handler: "index.handler",
},
authorizationType: sst.ApiAuthorizationType.NONE,
}
When u make a change to index.handler
and save, do u see
Building function index.handler
printed out in the terminal?Jan Plaček
03/01/2022, 10:53 AMJan Plaček
03/01/2022, 10:53 AMJan Plaček
03/01/2022, 10:55 AMFrank
Jan Plaček
03/01/2022, 11:04 AMfunction
like this:
"GET /dist": {
bundle: false,
srcPath: "dist/apps/lambda/",
handler: "index.handler",
authorizationType: sst.ApiAuthorizationType.NONE,
}Jan Plaček
03/01/2022, 11:04 AMauthorizationType
seems to be ignoredJan Plaček
03/01/2022, 11:05 AMFrank
function
prop in there.Frank
"GET /dist": {
function: {
bundle: false,
srcPath: "dist/apps/lambda/",
handler: "index.handler",
},
authorizationType: sst.ApiAuthorizationType.NONE,
}
or like this as a shortcut:
"GET /dist": {
bundle: false,
srcPath: "dist/apps/lambda/",
handler: "index.handler",
}
Frank
authorizationType
Frank
thdxr
03/01/2022, 12:33 PMJan Plaček
03/01/2022, 12:56 PMesbuild
not just some dependency (nestj
)thdxr
03/01/2022, 12:57 PMthdxr
03/01/2022, 12:59 PMJan Plaček
03/01/2022, 1:44 PMnestjs
. It's just a small prototype so rewriting would be fine. The bigger issue is developers that are familiar with it (they also use angular
which is very similar).
I set a goal to make it work if possible for now and then try to move (maybe gradually) away from. I don't want to immediately push us to unknown territory. Also, I really like the way sst
handles serverless development, but if a problem occurs I want to be able to fallback to previous setup.
I've already checked the thread and related issue on github, but thank you.
Btw the maturity of the project makes me a bit worried, but I am very pleased and surprised by the level of support here and the overall attitude.thdxr
03/01/2022, 1:46 PMJan Plaček
03/01/2022, 1:47 PMthdxr
03/01/2022, 1:50 PMJan Plaček
03/01/2022, 1:52 PMthdxr
03/01/2022, 1:53 PMthdxr
03/01/2022, 1:53 PMtsc
Jan Plaček
03/01/2022, 2:02 PMJan Plaček
03/01/2022, 2:06 PMesbuild
seems cool and all, but also quite young and opinionated. Supporting other bundlers somehow would be nice. I know there is an issue opened, just adding my vote 🙂thdxr
03/01/2022, 2:34 PMthdxr
03/01/2022, 2:34 PMJan Plaček
03/01/2022, 2:44 PMthdxr
03/01/2022, 2:48 PMthdxr
03/01/2022, 2:50 PMJan Plaček
03/01/2022, 3:36 PMsst
is very focused on DX, because other products seems to fall short in this regard.
However people are used to some tools, have certain knowledge, (bizzare) existing setups, opinions... for them it's not a question of speed, but whether they can use it or not.Jan Plaček
03/01/2022, 8:19 PMnestjs
app throws:
Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Runtime.HandlerNotFound: C:\\\\talsec-cloud\\\\.sst\\\\artifacts\\\\jplacek-sst-my-stack-Api-Lambda_GET_-dist\\\\dist\\\\apps\\\\lambda\\\\index.handler is undefined or not exported","reason":"Runtime.HandlerNotFound: C:\\\\talsec-cloud\\\\.sst\\\\artifacts\\\\jplacek-sst-my-stack-Api-Lambda_GET_-dist\\\\dist\\\\apps\\\\lambda\\\\index.handler is undefined or not exported","promise":{},"stack":["Runtime.UnhandledPromiseRejection: Runtime.HandlerNotFound: C:\\\\talsec-cloud\\\\.sst\\\\artifacts\\\\jplacek-sst-my-stack-Api-Lambda_GET_-dist\\\\dist\\\\apps\\\\lambda\\\\index.handler is undefined or not exported"," at process.<anonymous> (file:///C:/talsec-cloud/node_modules/@serverless-stack/aws-lambda-ric/lib/index.js:34:23)"," at process.emit (node:events:390:28)"," at process.emit (node:domain:475:12)"," at emit (node:internal/process/promises:136:22)"," at processPromiseRejections (node:internal/process/promises:242:25)"," at processTicksAndRejections (node:internal/process/task_queues:97:32)"]}
If I setup simple lambda function in the exactly the same way, it does work.
If I import somewhere both the bundled app and the simple lambda, they both export `handler`:
lambda { handler: [Function: handler] } // this is the bundled nestjs
bar { handler: [AsyncFunction (anonymous)] } // this is simple lambda
Frank
sst.json
at the root?Jan Plaček
03/02/2022, 8:02 AMJan Plaček
03/02/2022, 8:05 AMJan Plaček
03/02/2022, 8:08 AMJan Plaček
03/02/2022, 9:38 AMJan Plaček
03/02/2022, 10:52 AMindex.js
, it suddenly works:
const originalHandler = exports.handler;
exports.handler = async (event,ctx) => {
return originalHandler(event, ctx);
};
Jan Plaček
03/02/2022, 3:16 PMexports.handler = exports.handler;
Jan Plaček
03/02/2022, 3:16 PMthdxr
03/02/2022, 3:18 PMJan Plaček
03/02/2022, 3:18 PMJan Plaček
03/02/2022, 3:19 PMthdxr
03/02/2022, 3:19 PMlambda { handler: [Function: handler] } // this is the bundled nestjs
bar { handler: [AsyncFunction (anonymous)] } // this is simple lambda
It looks like it's getting double nested, module.exports.handler.handler
- we noticed this with default exports and wrote a workaround for itthdxr
03/02/2022, 3:20 PMJan Plaček
03/02/2022, 3:21 PMJan Plaček
03/02/2022, 3:25 PMconsole.log(module.exports.handler.handler);
console.log(exports.handler.handler);
both undefinedJan Plaček
03/02/2022, 3:27 PMexport.handler
being set dymaically in some self invoked function generated by webpackJan Plaček
03/02/2022, 3:29 PM