https://supertokens.com/ logo
#support-questions
with AWS lambda
# support-questions
m

mukulg22

04/25/2023, 4:56 AM
Hey I'm trying to setup the backend on AWS lambda. Currently we had it running on ECS. I have followed the ST documentation for Lambda setup and it seems to be incomplete as I'm new to lambda. I have created the layer and uploaded per the documentation and created 2 files (auth.js, config,js) but the Lambda is configured to index.handler which doesnt exists. What change should I make to get it working?
r

rp

04/25/2023, 6:41 AM
hey @mukulg22 @KShivendu can help here.
k

KShivendu

04/25/2023, 6:54 AM
> but the Lambda is configured to index.handler which doesnt exists Hi. which index.handler are you talking about? The default file given by AWS lambda in the browser IDE?
If yes, you can easily change that from its settings page. There's an option to set which function should be invoked.
m

mukulg22

04/25/2023, 6:59 AM
Hey @KShivendu Yes, the handler in AWS UI module.exports.handler = middy(middleware()).use(cors({ origin: getBackendConfig().appInfo.websiteDomain, credentials: true, headers: ["Content-Type", ...supertokens.getAllCORSHeaders()].join(", "), methods: "OPTIONS,POST,GET,PUT,DELETE" })).onError(request => { throw request.error; }); this is the method to be invoked right? effectively, index.handler should be module.exports.handler ?
This is the error I get when I update the handler { "errorType": "Runtime.HandlerNotFound", "errorMessage": "module.exports.handler is undefined or not exported", "trace": [ "Runtime.HandlerNotFound: module.exports.handler is undefined or not exported", " at Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1034:15)", " at async start (file:///var/runtime/index.mjs:1194:23)", " at async file:///var/runtime/index.mjs:1200:1" ] }
k

KShivendu

04/25/2023, 7:58 AM
indeed.
Ohh wait. What's the filename? auth.js, right?
Rename it to
index.js
OR change the handler from
index.handler
to
auth.handler
from the settings
m

mukulg22

04/26/2023, 6:04 AM
hey @User @KShivendu made the change you suggested. Facing the below logs. { "errorType": "TypeError", "errorMessage": "Cannot read properties of undefined (reading 'http')", "trace": [ "TypeError: Cannot read properties of undefined (reading 'http')", " at AWSRequest.getOriginalURL (/opt/nodejs/node_modules/supertokens-node/lib/build/framework/awsLambda/framework.js:125:50)", " at SuperTokens. (/opt/nodejs/node_modules/supertokens-node/lib/build/supertokens.js:211:61)", " at Generator.next ()", " at /opt/nodejs/node_modules/supertokens-node/lib/build/supertokens.js:44:75", " at new Promise ()", " at __awaiter (/opt/nodejs/node_modules/supertokens-node/lib/build/supertokens.js:26:16)", " at SuperTokens.middleware (/opt/nodejs/node_modules/supertokens-node/lib/build/supertokens.js:208:13)", " at /opt/nodejs/node_modules/supertokens-node/lib/build/framework/awsLambda/framework.js:283:48", " at Generator.next ()", " at /opt/nodejs/node_modules/supertokens-node/lib/build/framework/awsLambda/framework.js:30:75" ] }
r

rp

04/26/2023, 7:24 AM
can i see the relevant code you have added?
r

rp

04/26/2023, 7:41 AM
which version of the supertokens-node SDK are you using?
m

mukulg22

04/26/2023, 7:55 AM
"supertokens-node": "^13.5.0"
r

rp

04/26/2023, 8:08 AM
@iresharma can help here.
i

iresharma

04/26/2023, 10:39 AM
@mukulg22 are you testing the function using a custom event or the event is fired from our frontend SDK ?
m

mukulg22

04/26/2023, 11:20 AM
im testing the function using custom event. @iresharma
i

iresharma

04/26/2023, 12:14 PM
@mukulg22 are you using any template for the event type ?
because the way are SDK is written we only support events of type
apigateway-aws-proxy

https://cdn.discordapp.com/attachments/1100284079087308841/1100757572992118794/Screenshot_2023-04-26_at_5.47.23_PM.png

m

mukulg22

04/26/2023, 12:43 PM
@iresharma your previous response worked. Able to access the dashboard via url.
@iresharma I have another requirement. I need to secure certain routes with session verification and certain routes as open apis
What is the best way to get this done?
i

iresharma

04/26/2023, 1:04 PM
that's fine but event type is the correct way of testing this
don't add verify session middleware to routes that you want as open apis if you want optional session, there is a sessionRequired option that you can pass to verifySession (it's in our docs)