This is a document that explains how to run the server
on AWS via Express API using DynamoDB, Lambda and Gateway.
-
Execute setup pre-requisites, please install nodeJS first
sudo npm i -g serverless #install serverless for nodeJS cd server/ npm install #install dependencies for the server from package.json
-
Configuring AWS Keys for deployment
- You would need to configure your local machine with the appropriate keys to ensure that you have the right roles to deploy the services and files to AWS. You can do that by running the following code. You will not be able to deploy without these keys setup properly.
export AWS_ACCESS_KEY_ID="YOUR_KEY_ID" export AWS_SECRET_ACCESS_KEY="YOUR_AWS_SECRET_KEY"
-
Perform serverless login
serverless login
-
To deploy to AWS (Lambda/S3/DynamoDB or core logic)
Important Note: To update the
******
--stage variable to the right environment that is being usedserverless deploy --stage ****** serverless remove --stage ****** # to remove the deployed services
-
To export the server environment so that the the webclient "knows" where to call
- This is the file that the webclient loads to find the server URL. This file has a getter function that looks at the static website domain, and pick the right URL for the backend lambda server. Please update the path for
client/dist/assets/server.js
as appropriately needed when introducing new environments.
- This is the file that the webclient loads to find the server URL. This file has a getter function that looks at the static website domain, and pick the right URL for the backend lambda server. Please update the path for
-
To deploy to AWS (Static Files aka Static Web Pages or website)
Important Note: To update the
******
--stage variable to the right environment that is being usedserverless client deploy --stage ****** serverless client remove --stage ****** # to remove the deployed client
-
To deploy to different environments
Important Notes:
- By default the deploy happens to the "dev" channel, i.e. development environment of aws for testing. To deploy to production environment execute
- Deploy to production environment only after thorough testing in the development environment
serverless deploy --stage prod # for deploying the core logic to production environment, the DB, Lambda, S3 buckets are all different for this environment serverless client deploy --stage prod # for deploying the static website to production environment.
- This project uses Postman for API testing and you can download local copy of postman from https://www.postman.com/
- Postman collection is available at https://www.postman.com/sandeepzgk/workspace/vtgame-platform
- This collection is configured with the API and enviroment variables to test out the APIs
- Install Local SERVERLESS for Debug
serverless plugin install -n serverless-dynamodb-local serverless plugin install -n serverless-offline serverless plugin install -n serverless-s3-local serverless plugin install -n serverless-finch sls dynamodb install
- After that, running the following command with start both local API Gateway emulator as well as local instance of emulated DynamoDB:
serverless offline start --lambdaPort 3002 --httpPort 3000
Note: In current form, after deployment, your API is public and can be invoked by anyone. For production deployments, you might want to configure an authorizer. For details on how to do that, refer to httpApi
event docs. Additionally, in current configuration, the DynamoDB table will be removed when running serverless remove
. To retain the DynamoDB table even after removal of the stack, add DeletionPolicy: Retain
to its resource definition.