Our backend adopts a event-driven architecture, and uses the Serverless Framework to provision resources with EventBridge Infrastructure as Code.
The following are pre-requisites for setting up the development environment:
- Node 18.x and above
- Serverless Framework CLI
- AWS Amplify CLI
- AWS User Account with minimally
PowerUserAccess
andAdministratorAccess-Amplify
permissions - MongoDB Instance
git clone https://github.com/officeverse/backend.git
cd backend
npm install
rm -rf /amplify
amplify pull --appId <appId> --envName dev # Amplify CLI should already be comfigured
Add the following snippet into serverless.yml
:
custom:
s3:
host: localhost
directory: /tmp
resources:
Resources:
NewResource:
Type: AWS::S3::Bucket
Properties:
BucketName: local-bucket
The above snippet should be removed prior to deployment
Run the local deployment environment with npm run local
, which will start a local API Gateway server on http://localhost:3000
, and a S3 bucket on http://localhost:4569
.
Obtaining JWT for API Gateway
node -r dotenv/config scripts/cognitoLogin.mjs dotenv_config_path=.env.localThe resulting
AccessToken
should be passed into theAuthorization
header for authenticated access
To invoke functions locally
npx sls invoke local --function <functionName> --path <eventData>Example
Simulating a
PreSignUp
eventnpx sls invoke local --function preSignUpValidateCode --path events/preSignUpEvent.json
To put an object into the local bucket
bash scripts/localS3PutObject.sh <pathToFile>The file data will be stored in
/buckets/local-bucket
To deploy the backend, you may run npm run deploy
to provision resources on AWS servers.