with AWS lambda
# support-questions
m
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
hey @mukulg22 @KShivendu can help here.
k
> 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
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
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
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
can i see the relevant code you have added?
r
which version of the supertokens-node SDK are you using?
m
"supertokens-node": "^13.5.0"
r
@iresharma can help here.
i
@mukulg22 are you testing the function using a custom event or the event is fired from our frontend SDK ?
m
im testing the function using custom event. @iresharma
i
@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
@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
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)
2 Views