Skip to content

Commit 6ec18bc

Browse files
committed
initial
1 parent 4eb10f4 commit 6ec18bc

23 files changed

+3500
-0
lines changed

lib/xrp/cdk.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"app": "npx ts-node --prefer-ts-exts app.ts",
3+
"watch": {
4+
"include": [
5+
"**"
6+
],
7+
"exclude": [
8+
"README.md",
9+
"cdk*.json",
10+
"**/*.d.ts",
11+
"**/*.js",
12+
"tsconfig.json",
13+
"package*.json",
14+
"yarn.lock",
15+
"node_modules",
16+
"test"
17+
]
18+
},
19+
"context": {
20+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
21+
"@aws-cdk/core:checkSecretUsage": true,
22+
"@aws-cdk/core:target-partitions": [
23+
"aws",
24+
"aws-cn"
25+
],
26+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
27+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
28+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
29+
"@aws-cdk/aws-iam:minimizePolicies": true,
30+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
31+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
32+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
33+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
34+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
35+
"@aws-cdk/core:enablePartitionLiterals": true,
36+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
37+
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
38+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
39+
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
40+
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
41+
"@aws-cdk/aws-route53-patters:useCertificate": true,
42+
"@aws-cdk/customresources:installLatestAwsSdkDefault": false
43+
}
44+
}

lib/xrp/doc/README.md

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# Sample AWS Blockchain Node Runner app for XRP Nodes
2+
3+
| Contributed by |
4+
|:--------------------------------:|
5+
| Pedro Aceves <br/>[email protected] |
6+
7+
XRP node deployment on AWS. All nodes are configure as ["Stock Servers"](https://xrpl.org/docs/infrastructure/configuration/server-modes/run-rippled-as-a-stock-server)
8+
9+
## Overview of Deployment Architectures for Single and HA setups
10+
11+
### Single node setup
12+
13+
![Single Node Deployment](./assets/Architecture-Single%20node.drawio.png)
14+
15+
1. A XRP node deployed in the [Default VPC](https://docs.aws.amazon.com/vpc/latest/userguide/default-vpc.html) continuously synchronizes with the rest of nodes on the configured xrp network through [Internet Gateway](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Internet_Gateway.html).
16+
2. The XRP node is used by dApps or development tools internally from within the Default VPC. RPC API is not exposed to the Internet directly to protect nodes from unauthorized access.
17+
3. The XRP node sends various monitoring metrics for both EC2 and current XRP ledger sequence to Amazon CloudWatch. It also updates the dashboard with correct storage device names to display respective metrics properly.
18+
19+
### HA setup
20+
21+
![Highly Available Nodes Deployment](./assets/Architecture-HA%20Nodes.drawio.png)
22+
23+
1. A set of XRP nodes are deployed within an [Auto Scaling Group](https://docs.aws.amazon.com/autoscaling/ec2/userguide/auto-scaling-groups.html) in the [Default VPC](https://docs.aws.amazon.com/vpc/latest/userguide/default-vpc.html) continuously synchronizing with the rest of nodes on the configured xrp network through [Internet Gateway](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Internet_Gateway.html).
24+
2. The XRP nodes are accessed by dApps or development tools internally through [Application Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html). RPC API is not exposed to the Internet to protect nodes from unauthorized access.
25+
3. The XRP nodes send various monitoring metrics for EC2 to Amazon CloudWatch.
26+
27+
## Setup Instructions
28+
29+
### Open AWS CloudShell
30+
31+
To begin, ensure you login to your AWS account with permissions to create and modify resources in IAM, EC2, EBS, VPC, S3, KMS, and Secrets Manager.
32+
33+
From the AWS Management Console, open the [AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/welcome.html), a web-based shell environment. If unfamiliar, review the [2-minute YouTube video](https://youtu.be/fz4rbjRaiQM) for an overview and check out [CloudShell with VPC environment](https://docs.aws.amazon.com/cloudshell/latest/userguide/creating-vpc-environment.html) that we'll use to test nodes API from internal IP address space.
34+
35+
Once ready, you can run the commands to deploy and test blueprints in the CloudShell.
36+
37+
### Clone this repository and install dependencies
38+
39+
```bash
40+
git clone https://github.com/aws-samples/aws-blockchain-node-runners.git
41+
cd aws-blockchain-node-runners
42+
npm install
43+
```
44+
45+
### Configure your setup
46+
47+
1. Make sure you are in the root directory of the cloned repository
48+
49+
2. If you have deleted or don't have the default VPC, create default VPC
50+
51+
```bash
52+
aws ec2 create-default-vpc
53+
```
54+
55+
> **NOTE:** *You may see the following error if the default VPC already exists: `An error occurred (DefaultVpcAlreadyExists) when calling the CreateDefaultVpc operation: A Default VPC already exists for this account in this region.`. That means you can just continue with the following steps.*
56+
57+
3. Configure your setup
58+
59+
Create your own copy of `.env` file and edit it to update with your AWS Account ID and Region:
60+
```bash
61+
cd lib/xrp
62+
cp ./sample-configs/.env-xrp-testnet .env
63+
nano .env
64+
```
65+
> **NOTE:** *You can find more examples inside `sample-configs` *
66+
67+
68+
4. Deploy common components such as IAM role:
69+
70+
```bash
71+
npx cdk deploy XRP-common
72+
```
73+
74+
75+
### Deploy a Single Node
76+
77+
1. Deploy the node
78+
79+
```bash
80+
npx cdk deploy XRP-single-node --json --outputs-file single-node-deploy.json
81+
```
82+
83+
2. After starting the node you need to wait for the initial synchronization process to finish. You can use Amazon CloudWatch to track the progress. There is a script that publishes CloudWatch metrics every 5 minutes, where you can watch `XRP Sequence` metrics. When the node is fully synced the sequence should match that of the configured xrp network (testnet, mainnet, etc). To see them:
84+
85+
- Navigate to [CloudWatch service](https://console.aws.amazon.com/cloudwatch/) (make sure you are in the region you have specified for `AWS_REGION`)
86+
- Open `Dashboards` and select dashboard that starts with `XRP-single-node` from the list of dashboards.
87+
88+
### Deploy HA Nodes
89+
90+
1. Deploy multiple HA Nodes
91+
92+
```bash
93+
pwd
94+
# Make sure you are in aws-blockchain-node-runners/lib/xrp
95+
npx cdk deploy XRP-ha-nodes --json --outputs-file ha-nodes-deploy.json
96+
```
97+
98+
2. Give the new nodes time to initialize
99+
100+
> **NOTE:** *By default and for security reasons the load balancer is available only from within the default VPC in the region where it is deployed. It is not available from the Internet and is not open for external connections. Before opening it up please make sure you protect your RPC APIs.*
101+
102+
### Clearing up and undeploy everything
103+
104+
Destroy HA Nodes, Single Nodes and Common stacks
105+
106+
```bash
107+
# Setting the AWS account id and region in case local .env file is lost
108+
export AWS_ACCOUNT_ID=<your_target_AWS_account_id>
109+
export AWS_REGION=<your_target_AWS_region>
110+
111+
pwd
112+
# Make sure you are in aws-blockchain-node-runners/lib/xrp
113+
114+
# Destroy HA Nodes
115+
cdk destroy XRP-ha-nodes
116+
117+
# Destroy Single Node
118+
cdk destroy XRP-single-node
119+
120+
# Delete all common components like IAM role and Security Group
121+
cdk destroy XRP-common
122+
```
123+
124+
### FAQ
125+
126+
1. How to check the logs from the EC2 user-data script?
127+
128+
```bash
129+
pwd
130+
# Make sure you are in aws-blockchain-node-runners/lib/xrp
131+
132+
export INSTANCE_ID=$(cat single-node-deploy.json | jq -r '..|.node-instance-id? | select(. != null)')
133+
echo "INSTANCE_ID=" $INSTANCE_ID
134+
aws ssm start-session --target $INSTANCE_ID --region $AWS_REGION
135+
sudo cat /var/log/cloud-init-output.log
136+
sudo cat /var/log/user-data.log
137+
```
138+
2. How can I change rippled (XRP) configuration?
139+
There are two places of configuration for the xrp nodes:
140+
141+
a. .env file. Here is where you specify the xrp network you want. This is the key into the config hash in part b
142+
```bash
143+
HUB_NETWORK_ID="testnet"
144+
```
145+
146+
b. lib/xrp/lib/assets/rippled/rippledconfig.py file. Here you can setup listners an network configuration for the network specified in part "a"
147+
148+
149+
131 KB
Loading
99.1 KB
Loading

lib/xrp/lib/assets/cw-agent.json

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"agent": {
3+
"metrics_collection_interval": 60,
4+
"run_as_user": "root"
5+
},
6+
"metrics": {
7+
"aggregation_dimensions": [
8+
[
9+
"InstanceId"
10+
]
11+
],
12+
"append_dimensions": {
13+
"InstanceId": "${aws:InstanceId}"
14+
},
15+
"metrics_collected": {
16+
"cpu": {
17+
"measurement": [
18+
"cpu_usage_idle",
19+
"cpu_usage_iowait",
20+
"cpu_usage_user",
21+
"cpu_usage_system"
22+
],
23+
"metrics_collection_interval": 60,
24+
"resources": [
25+
"*"
26+
],
27+
"totalcpu": false
28+
},
29+
"disk": {
30+
"measurement": [
31+
"used_percent"
32+
],
33+
"metrics_collection_interval": 60,
34+
"resources": [
35+
"*"
36+
]
37+
},
38+
"diskio": {
39+
"measurement": [
40+
"io_time",
41+
"write_bytes",
42+
"read_bytes",
43+
"writes",
44+
"reads",
45+
"write_time",
46+
"read_time",
47+
"iops_in_progress"
48+
],
49+
"metrics_collection_interval": 60,
50+
"resources": [
51+
"*"
52+
]
53+
},
54+
"mem": {
55+
"measurement": [
56+
"mem_used_percent",
57+
"mem_cached"
58+
],
59+
"metrics_collection_interval": 60
60+
},
61+
"netstat": {
62+
"measurement": [
63+
"tcp_established",
64+
"tcp_time_wait"
65+
],
66+
"metrics_collection_interval": 60
67+
},
68+
"swap": {
69+
"measurement": [
70+
"swap_used_percent"
71+
],
72+
"metrics_collection_interval": 60
73+
}
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)