Creates Infrastructure on AWS to deploy Polygon-Edge:
- VPC if not present (pass existing VPC to use the same)
- ECR repo, (Also builds and pushes Docker Image to ECR repo during
cdk deploy
) - EFS for storing blockchain state persistently.
- ECS Service and Task Definition with 4 ECS containers for validators
- All containers can communicate each other via localhost since they are under ECS service and task-definition with network-mode as
awsvpc
- If for some reasons, you need to separate the validator nodes into separate ECS services, then App-Mesh can be integrated.
- This cut downs Loadbalancers, DNS query costs.
- All containers can communicate each other via localhost since they are under ECS service and task-definition with network-mode as
- IF ALB (Application Load Balancer) doesn't exist, it creates ALB, Target groups, Listener Rules and ACM certificate
- If ALB exists and want to use the same, pass
ALB_EXISTS
as true in the config, but have to create Target groups, Listener Rule and hosted zone manually.
- If ALB exists and want to use the same, pass
- Creates HostedZone if it doesn't exist. Configure if already exists
This package also has code to create Polygon-Edge Blockchain (Checkout src/validator
)
- It Creates Genesis file if not present and store the secrets in SSM parameter store for first time.
- It persists the blockchain state in EFS and starts validator node(server).
- The validator node can be restarted, it will use existing genesis file and blockchain state
- Creates 4 validator nodes as recommended for crash Tolerance and BFT Guarantee. Reference
- validator1 node creates the
genesis.json
file for first time if not present and stores the secrets in SSM Parameter store if STAGE is not "localhost" - Out of 4 nodes, only validator1's JSONRPC_PORT (10002) is exposed to public.
- The domain would be as configured in config directory. ex:
https://blockchain.your-company.com
- The domain would be as configured in config directory. ex:
npm 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 cdk.json
file tells the CDK Toolkit how to execute your app.
- Create
config/[STAGE].json
file ex:config/prod.json
NOTE:
- config package is used, hence config/prod.json can be accessed when NODE_ENV is set to prod
- default.json is used by default for any NODE_ENV
Configure your details, (There exists config/default.json
file to start with)
{
"STAGE": "prod", // use "localhost" if you don't want to store the secrets in SSM parameter store
"ACCOUNT_ID": "XXX511334XXX", // AWS Account ID
"REGION": "us-west-1", // AWS region to deploy the stack
// wallet account address, This account will be pre-mined with tokens
"GENESIS_ACCOUNT": "0xXXXX4Af469FE0F501a0A94c2f45EXXXXXXXXX03",
"PREMINE_NUM_TOKENS_IN_WEI": "100000000000000000000000000",
"BLOCKCHAIN_NAME": "YOUR_BLOCKCHAIN_NAME",
// if you want your blockchain to be reachable by say blockchain.your-company.com
// AWS needs a hosted-zone in Route53 with your-company.com
// Don't worry if not created, this will be handled by the CDK.
"HOSTED_ZONE_NAME": "your-company.com",
"SUBDOMAIN": "blockchain", //FQDN (Fully qualified domain name would be blockchain.your-company.com)
"OPTIONAL_EXISTING_HOSTED_ZONE_ID": "Z3TRGGK18XXXXX",
"OPTIONAL_EXISTING_VPC_ID": "",
"ALB_EXISTS": false
}
- Get AWS Credentials, Can have two Roles.
- Admin Access
- This is to deploy Bootstrap stack (CDKToolKit), This is one time action and prerequisite for deploying InfraStack
- This deploys necessary artifacts used by the Infra stack.
- After bootstrapping Admin access can be removed.
- CDK Deployment Role
- This is to deploy Infra stack, this will have all minimal permissions to deal with CDK.
- IAM Role should be having below Policy Statement.
{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["sts:AssumeRole"],"Resource":["arn:aws:iam::*:role/cdk-*"]}]}
- Admin Access
- Configure aws profile by getting aws credentials. Don't need to use
--profile
anywhere if you already have admin access as default.aws configure --profile [profile_name]
- Deploy the cdk bootstrap (use admin access Role)
cdk bootstrap --profile [profile_name]
- Deploy the stack (Recommended: use cdk deployment Role's profile)
cdk deploy --profile [profile_name]
NOTE: If your domain is not validated in AWS, CDK waits until the validation is done. This would send mails to listed emails. Reference
- There might be situations where you want to recreate your blockchain with some modified parameters. ex: with an increase in premined tokens. Once genesis.json file is created, most of the parameters are not modifiable, hence blockchain has to be recreated.
Steps in the same order:
- Delete the ECR repo created by CDK manually. This is a stateful resource and had to be deleted manually.
- Delete the Infra stack, either from AWS cloudformation or using
cdk destroy --profile [profile_name]
Note: No need to delete the Bootstrap stack. - Delete the EFS if not needed, this is a stateful resource and will be skipped when stack is deleted, hence this has to be deleted manually
- Delete the records from AWS SSM parameter store with Key prefix "/blockchain/validator"