This is a project for Multi-Tenant Serverless API development with AWS Cloud Development Kit (CDK) using TypeScript. It comes with all the necessary code to develop and deploy a Serverless GraphQL API in the AWS Cloud. This includes the provisioning of cloud infrastructure in code and Serverless stubs where developers may easily include their business logic. The project also provides pre-built mock lambda functions and unit tests to test your deployed APIs.
The project code may be conceptually divided into two parts:
- The code that is generated by the Panacloud CLI, and will continuously be updated by the CLI as your API schema evolves. If the developer edits and updated this code, it will be overwritten next time the schema is updated and Panacloud CLI update command is given.
- The code that the developer edits and updates and contains the business logic for the APIs. This code is contained in the
editable_src/
directory.
It is highly recommended that the developer only edit and update the code contained in the editable_src/
directory because the rest of the code is generated and updated by the Panacloud CLI.
The generated project code includes the mock lambdas contained in the mock_lambda
directory in the root project folder. Typically, the developer will write business logic in the stub lambdas contained in the editable_src/lambdas/
directory. The configuration contained in the editable_src/panacloudconfig.json
file decides which lambda the APIs will call. Therefore, the project may be using mock lambdas in some calls and the real stub lambdas in other calls. This flexibility allows the developer to seamlessly transition from mock APIs towards real APIs, without the API users and testers even noticing it. Also, the mock APIs may be deployed right away.
The API CDK stack (cloud infrastructure in code) is generated by the Panacloud CLI panacloud init
command given the API schema. API development is an iterative process, therefore when the developer updates the API schema in the editable_src/graphql/schema/
directory and runs the panacloud update
command the project's CDK code is updated. Given this cycle, most of the CDK stack is generated and updated by the Panacloud CLI. However, the developer has the flexibility to add and update the CDK stack by adding and updating visitors in the editable_src/aspects/
directory. The Panacloud framework uses Aspects to enhance generated constructs and add cloud constructs written by the API developers.
The editable_src/
directory contains all the code which the developer edits.
The editable_src/lambdas/
directory contains all the lambda stubs where the developer writes the business logic.
The editable_src/panacloudconfig.json
file tells the Panacloud framework which lambda functions to call.
The editable_src/aspects
directory contains all the CDK code which the developer adds to the project CDK stack.
The cdk.json
file tells the CDK Toolkit how to execute your app.
Note: The official documentation of CDK version 2 is available here
Before we proceed to deploy the project lets first understand what it contains.
If you have already not done so, you need to bootstrap the cdk by using this command:
cdk bootstrap
Once we are done with bootstrapping we want to deploy the Mock Serverless APIs.
The project is already generated for you, you just have to compile it:
npm run build
You may now deploy the project for development stage:
npm run deploy-dev
After deploying check out the cdk-dev-outputs.json
file in the project root it contains the URL and Key of the deployed APIs.
You may now deploy the project for production stage:
npm run deploy-prd
After deploying check out the cdk-prd-outputs.json
file in the project root it contains the URL and Key of the deployed APIs.
After a deployment of dev stage is successuful you can run the automated tests on the deployed API:
npm run test-dev
After a deployment of production stage is successuful you can run the automated tests on the deployed API:
npm run test-prd
You can call the APIs by using this command which will open an client for your API:
panacloud client
Note: Right now you are running mock APIs therefore it will only give you responses to mock queries with fixed data.
For example, the mock data for the user query is in the mock_lambda_layer/mockData/user
file of your generated project. Therefore, only those queries will be successful which will use this mock data.
Now you may destroy the deployed development stage just give this command:
npm run destroy-dev
Now you may destroy the deployed production stage just give this command:
npm run destroy-dev
panacloud update
updates the generated code and is run after updating the schema in theeditable_src/graphql/schema/
directorynpm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testscdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template
The Panacloud Dapp and protocol complements the Panacloud CLI and facilitates you, the API developer to:
- Tokenize your APIs and raise funding for API development.
- Document your ownership of the API by issuing you an NFT.
- Market your APIs to the application developers in the API bazaar/store.
- Create a decentralized autonomous organization (DAO) for your APIs for governance in which the API token holders i.e. you, investors, and users can participate.
- Monitor your APIs and do multi-tenant billing and clearing on the Ethereum blockchain using smart contracts.
- Issue tokens to your API early adopters and users to incentivize them to subscribe and use your APIs and become a participant in the Owership Economy.
- Cash out whenever you require liquidity by selling your API tokens.