2. Backend config
#
1) Create Lambda layer with required libraries- NodeJS
- Python
mkdir lambda && cd lambda
npm i -s supertokens-node @middy/core @middy/http-cors
mdkir nodejs && cp -r node_modules nodejs
zip -r supertokens-node.zip nodejs/
mkdir lambda && cd lambda
pip install --target ./python fastapi uvicorn mangum nest_asyncio supertokens-python
cd python && rm -r *dist-info **/__pycache__ && cd ..
zip -r supertokens-python.zip python/
#
2) Upload SuperTokens lambda layerOpen AWS Lambda dashboard and click on layers:
Click "Create Layer" button:
Give a name for your layer, upload the zip and select the runtime
- NodeJS
- Python
#
3) Link lambda layer with lambda functionScroll to the bottom and look for the
Layers
tab. Click onAdd a layer
Select
Custom Layer
and then select the layer we created in the first step:
- NodeJS
- Python
#
4) Create a backend config fileUsing the editor provided by AWS, create a new config file and write the following code:
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
.