/qldb-wallet

Primary LanguageTypeScript

QLDB DynamoDB Serverless Wallet

This is NodeJs(Typescript) Digital Wallet API Project based on AWS serverless-wallet blog

API Parameters

Get APIs require GET method with pathParameters, while others require POST method with body. The body of the request must be a JSON object with the following attributes: "requestTime" works as idempotency key and must be specified by client side.

  • /getBalance(GET): /{accountId}
  • /getTransactions(GET): /{accountId}?afterTime={timestamp}&beforeTime={timestamp}
  • /createAccount(POST): { "accountId": <string> }
  • /deleteAccount(POST): { "accountId": <string> }
  • /updateBalance(POST): { "accountId": <string>, "amount": <number>, requestTime: <ISO8601 string> }
  • /transferFunds(POST): { "fromAccountId": <string>, "toAccountId": <string>, "amount": <number>, requestTime: <ISO8601 string> }
  • /addTransaction(POST): { "accountId": <string>, "amount": <number>, requestTime: <ISO8601 string> }
  • /closeTransaction(POST): { "accountId": <string>, requestTime: <ISO8601 string>, status: <string> }

The cdk.json file tells the CDK Toolkit how to execute your app.

Architecture

This project will deploy digital wallet service using serverless technologies on AWS. Including:

  • REST API on API Gateway
  • Lambda Functions
  • QLDB Ledger
  • QLDB Ledger stream and Kinesis Data Stream
  • DynamoDB Table
  • IAM roles

architecture diagram

Useful commands

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile
  • npm run test perform the jest unit tests
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk synth emits the synthesized CloudFormation template

Process log to deploy CDK (with Macbook Pro Apple Silicon)

  1. Follow instruction to set up CDK

    • Install awscli via brew --> aws command failed --> Install six via brew
    • Install aws-cdk
    • aws configure sso
    • cdk bootstrap aws://ACCOUNT-NUMBER/REGION --> Error: "no credentials have been configured" --> Look into the hidden files ~/.aws/config and ~/.aws/credentials, then copy and paste the value from "Coomand line or programmatic access" popup SSO login screen. (Credential often expires hence need to update ~/.aws/credentials everytime.)
  2. Folow instruction to deploy CDK

    • Test deploy: cdk init app --language typescript, npm run build, cdk ls, cdk synth, cdk deploy
    • Add actual code based on AWS Sample serverless-wallet (Python)
    • cdk deploy --> Error: "Ledger is not yet active" --> Deploy only creating QLDB and DynamoDB portion first, then after confirming Ledger is active, deploy all.

Post-deployment setup

  1. Create the QLDB table. You may use the QLDB query editor on the Amazon QLDB Console to execute these queries. The table name must match the 'qldb_table_name' parameter in config.py: -- CREATE TABLE "<qldb_table_name>"

  2. Create an index on the table for the accountId attribute: -- CREATE INDEX ON "<qldb_table_name>" (accountId)