https://supertokens.com/ logo
Title
b

Bralz

12/01/2022, 3:57 PM
Copying the example from (https://github.com/supertokens/supertokens-auth-react/tree/master/examples/with-aws-lambda/backend) and I'm getting the following error in Lambda:
r

rp

12/01/2022, 4:03 PM
Hey! Can you instead use the code snippets in the docs? The example app above might be outdated slightly
b

Bralz

12/01/2022, 4:14 PM
The only difference in that doc is that there are import statements instead of require. Are we meant to include a package.json with the lambda then?
Hmm looking through the docs more a lot of the aws lambda stuff is also in typescript
r

rp

12/01/2022, 5:05 PM
Yea. All the code snippets are in typescript in the docs.
> Are we meant to include a package.json with the lambda then? Yes.
If you are getting the same error, please post the code that you have added in the lambda here.
b

Bralz

12/01/2022, 9:57 PM
I will try again to make a Lambda tonight using a layer for the supertokens module. It would be helpful if at some point we could get a hello-world example that includes the javascript/package.json for everything as IIRC you have to jump through some hoops to use ts in lambda.
r

rp

12/02/2022, 2:36 AM
Fair enough! Noted.
b

Bralz

12/02/2022, 2:17 PM
Ok so when changing the type to module within package.json and using ESM imports I get the following error:
{
  "errorType": "Error",
  "errorMessage": "Directory import '/var/task/node_modules/supertokens-node/framework/awsLambda' is not supported resolving ES modules imported from /var/task/index.js\nDid you mean to import supertokens-node/framework/awsLambda/index.js?",
  "trace": [
    "Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/var/task/node_modules/supertokens-node/framework/awsLambda' is not supported resolving ES modules imported from /var/task/index.js",
    "Did you mean to import supertokens-node/framework/awsLambda/index.js?",
    "    at new NodeError (node:internal/errors:393:5)",
    "    at finalizeResolution (node:internal/modules/esm/resolve:324:17)",
    "    at moduleResolve (node:internal/modules/esm/resolve:965:10)",
    "    at moduleResolveWithNodePath (node:internal/modules/esm/resolve:909:12)",
    "    at defaultResolve (node:internal/modules/esm/resolve:1173:79)",
    "    at nextResolve (node:internal/modules/esm/loader:163:28)",
    "    at ESMLoader.resolve (node:internal/modules/esm/loader:841:30)",
    "    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)",
    "    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)",
    "    at link (node:internal/modules/esm/module_job:75:36)"
  ]
}
And when using require statements without a module type I get this error:
{
  "errorType": "TypeError",
  "errorMessage": "Cannot read properties of undefined (reading 'http')",
  "trace": [
    "TypeError: Cannot read properties of undefined (reading 'http')",
    "    at AWSRequest.getOriginalURL (/var/task/node_modules/supertokens-node/lib/build/framework/awsLambda/framework.js:117:50)",
    "    at SuperTokens.<anonymous> (/var/task/node_modules/supertokens-node/lib/build/supertokens.js:227:61)",
    "    at Generator.next (<anonymous>)",
    "    at /var/task/node_modules/supertokens-node/lib/build/supertokens.js:44:75",
    "    at new Promise (<anonymous>)",
    "    at __awaiter (/var/task/node_modules/supertokens-node/lib/build/supertokens.js:26:16)",
    "    at SuperTokens.middleware (/var/task/node_modules/supertokens-node/lib/build/supertokens.js:224:13)",
    "    at /var/task/node_modules/supertokens-node/lib/build/framework/awsLambda/framework.js:264:48",
    "    at Generator.next (<anonymous>)",
    "    at /var/task/node_modules/supertokens-node/lib/build/framework/awsLambda/framework.js:30:75"
  ]
}
I beleive both of these issues are occurring when trying to import middleware from supertokens-node/framework/awsLambda
Ah so I put a console.log() sattement in the aws lambda framework for the missing "http" problem and found that the event doesn't have anything in it besides my test event's details. So perhaps this works with a live invocation but not when kicking off a test event.
r

rp

12/02/2022, 2:36 PM
Hmmm. Interesting.
Try with the live invocation and see if it works
If you can open an issue about this, we can have a look at it sometime next week
b

Bralz

12/02/2022, 2:37 PM
ok here is the console log output btw. i was just running a test in the aws console to see what would come out of an invocation
r

rp

12/02/2022, 2:39 PM
I see
b

Bralz

12/02/2022, 2:39 PM
It appears to be just a simple matter of the module not spoofing some event details for testing purposes. Could probably be solved by having some flag for testing that writes them into the event.
r

rp

12/02/2022, 2:40 PM
Yeaaa. Probably
b

Bralz

12/02/2022, 3:14 PM
Or just make a note in the lambda docs with a testing template containing the details. I assume a lot of people might run a simple aws console test after setting up their lambda to see if it works.
r

rp

12/02/2022, 3:14 PM
Yea. That’s a good idea. Will do that anyway. Thanks