Skip to main content

2. Backend config

1) Create Lambda layer with required libraries#

mkdir lambda && cd lambda

npm i -s supertokens-node @middy/core@4.5.5 @middy/http-cors@4.5.5
mkdir nodejs && cp -r node_modules nodejs
zip -r supertokens-node.zip nodejs/

2) Upload SuperTokens lambda layer#

3) Link lambda layer with lambda function#

  • Scroll to the bottom and look for the Layers tab. Click on Add a layer

  • Select Custom Layer and then select the layer we created in the first step:

4) Create a backend config file#

Using the editor provided by AWS, create a new config file and write the following code:

config.js
import EmailPassword from "supertokens-node/recipe/emailpassword";
import Session from "supertokens-node/recipe/session";

function getBackendConfig() {
return {
framework: "awsLambda",
supertokens: {
connectionURI: "",
apiKey: "",
},
appInfo: {
// learn more about this on https://supertokens.com/docs/emailpassword/appinfo
appName: "<YOUR_APP_NAME>",
apiDomain: "<YOUR_API_DOMAIN>",
websiteDomain: "<YOUR_WEBSITE_DOMAIN>",
apiBasePath: "/auth",
websiteBasePath: "/auth",
apiGatewayPath: "/dev"
},
recipeList: [
EmailPassword.init(),
Session.init(),
],
isInServerlessEnv: true,
}
}

module.exports.getBackendConfig = getBackendConfig;
important

In the above code, notice the extra config of apiGatewayPath that was added to the appInfo object. The value of this should be whatever you have set as the value of your AWS stage which scopes your API endpoints. For example, you may have a stage name per dev environment:

  • One for development (/dev).
  • One for testing (/test).
  • One for prod (/prod).

So the value of apiGatewayPath should be set according to the above based on the env it's running under.

You also need to change the apiBasePath on the frontend config to append the stage to the path. For example, if the frontend is query the development stage and the value of apiBasePath is /auth, you should change it to /dev/auth.