Nine Chronicles In-app Purchase Service
- Python 3.10
- NodeJS 18 LTS
- Postgresql 15.2
NineChronicles.IAP has 4 parts mainly.
Each part is separated project and uses different virtualenv.
Please carefully check current env not to confuse which virtualenv to use.
AWS CDK to build and deploy services.
This project itself does not have any application/logic code in it.
If you want to manage AWS Stack and services, here is right place to see.
Common modules used from another services.
This manages DB model, revision and provides DB connector.
Main service of NineChronicles.IAP.
This has FastAPI backend and Svelte Frontend backoffice.
AWS Lambda worker functions to process message to NineChronicles Action and monitor blockchain.
Each project has own `pyproject.toml` and should be set on separated venv.
Please follow carefully instructions and double check everytime you work.
poetry env use python3.10
poetry shell
poetry install
exit # This does not close your terminal, exit from poetry venv session.
pushd common
poetry shell # Please make sure you have new poetry environment with seeing venv name
poetry install
exit
popd
pushd iap
poetry shell # Please make sure you have new poetry environment with seeing venv name
poetry install
exit
popd
pushd worker
poetry shell # Please make sure you have new poetry environment with seeing venv name
poetry install
exit
popd
NineChronicles.IAP/common
manages DB schema using alembic.
Please install PostgreSQL and run psql server before run alembic.
pushd common
poetry shell
cp alembic.ini.example alembic.ini
Open alembic.ini file and edit sqlalchemy.url
around line 60 to your local DB.
Then use alembic command to migrate to latest DB schema.
alembic upgrade head
exit
popd
NineChronicles.IAP/iap
uses Svelte ad frontend.
It can be served by vite, but we'll build fronetend app because it's closer to production.
cd iap/frontend
yarn
yarn build --watch # Rebuild changes are detected
NineChronicles.IAP/iap
uses FastAPI as backend.
You should config your own settings to run backend app.
cd iap/settings
cp local.py.example local.py
cd ..
Open iap/settings/local.py and set all values to your own.
IAP validation URLs are set to validate sandbox receipts only. For production, you have to change these URLs to
production URLs.
Now you can run backend app on your local env.
poetry shell
cd .. # Move back to project root to import all packages and modules.
env=local uvicorn iap.main:app --reload
You can set env=local
environment variable with your favorite ways.
NineChronicles.IAP uses AWS CDK to build and deploy application to AWS.
There are several ways to deploy lambda functions to AWS.
In this document, only "IAM user with credentials" case is covered.
- Create or select IAM user for CDK.
- Setup IAM permissions.
You can referenceiam_role_example.json
to check what permissions are required to where. - Create credentials and set it to your local machine.
- You can set it to
~/.aws/credentials
- You can set it to
Replace [AWS_PROFILE]
to your profile name in following commands.
Functions in NineChronicles.IAP cannot run itself without dependencies and AWS Lambda Layer ca do this.
Since we're managing packages using poetry, we need to make directory with dependent packages for lamda layer.
# For iap service
pushd iap
poetry shell
poetry export --without-hashes -o requirements.txt
pip install -r requirements.txt -t layer/python/lib/python3.10/site-packages/ --upgrade
exit
popd
# For worker
pushd worker
poetry shell
poetry export --without-hashes -o requirements.txt
pip install -r requirements.txt -t layer/python/lib/python3.10/site-packages/ --upgrade
exit
popd
cdk synth --profile [AWS_PROFILE]
You have to bootstrap CDK when you're very first time to deploy stack on your AWS account.
You don't need to check whether this step is required or not. Just run step 4
and the CDK will let you know if you
need to bootstrap.
cdk bootstrap --profile [AWS_PROFILE]
cdk deploy --profile [AWS_PROFILE] --app "cdk.out" --all