Skip to content

Commit a579cd3

Browse files
committed
Allora. Refactored CDK and user-data. Node failes to start
1 parent dd9d1cd commit a579cd3

27 files changed

+1250
-1671
lines changed

lib/allora/README.md

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,20 @@ This is the Well-Architected checklist for the Allora worker nodes implementatio
8080

8181
## Setup Instructions
8282

83-
### Setup Cloud9
83+
### Open AWS CloudShell
8484

85-
We will use AWS Cloud9 to execute the subsequent commands. Follow the instructions in [Cloud9 Setup](../../docs/setup-cloud9.md).
85+
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.
86+
87+
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.
88+
89+
Once ready, you can run the commands to deploy and test blueprints in the CloudShell.
8690

8791
### Clone this repository and install dependencies
8892

8993
```bash
90-
git clone https://github.com/aws-samples/aws-blockchain-node-runners.git
91-
cd aws-blockchain-node-runners
92-
npm install
94+
git clone https://github.com/aws-samples/aws-blockchain-node-runners.git
95+
cd aws-blockchain-node-runners
96+
npm install
9397
```
9498

9599
### Deploy single worker node
@@ -99,67 +103,67 @@ We will use AWS Cloud9 to execute the subsequent commands. Follow the instructio
99103
2. Configure your setup
100104

101105
Create your own copy of `.env` file and edit it to update with your AWS Account ID and Region:
102-
```bash
103-
# Make sure you are in aws-blockchain-node-runners/lib/allora
104-
cd lib/allora
105-
npm install
106-
pwd
107-
cp ./sample-configs/.env-sample-full .env
108-
nano .env
109-
```
110-
> NOTE:
111-
> Example configuration parameters are set in the local `.env-sample` file. You can find more examples inside `sample-configs` directory.
112-
113-
> IMPORTANT:
114-
> All AWS CDK v2 deployments use dedicated AWS resources to hold data during deployment. Therefore, your AWS account and Region must be [bootstrapped](https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping.html) to create these resources before you can deploy. If you haven't already bootstrapped, issue the following command:
115-
> ```bash
116-
> cdk bootstrap aws://ACCOUNT-NUMBER/REGION
117-
> ```
106+
```bash
107+
# Make sure you are in aws-blockchain-node-runners/lib/allora
108+
cd lib/allora
109+
npm install
110+
pwd
111+
cp ./sample-configs/.env-sample-full .env
112+
nano .env
113+
```
114+
> NOTE:
115+
> Example configuration parameters are set in the local `.env-sample` file. You can find more examples inside `sample-configs` directory.
118116
119-
3. Deploy Common Stack
117+
> IMPORTANT:
118+
> All AWS CDK v2 deployments use dedicated AWS resources to hold data during deployment. Therefore, your AWS account and Region must be [bootstrapped](https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping.html) to create these resources before you can deploy. If you haven't already bootstrapped, issue the following command:
119+
> ```bash
120+
> cdk bootstrap aws://ACCOUNT-NUMBER/REGION
121+
> ```
120122
121-
```bash
122-
pwd
123-
# Make sure you are in aws-blockchain-node-runners/lib/allora
124-
npx cdk deploy allora-edge-common --json --outputs-file allora-edge-common-deploy.json
125-
```
123+
3. Deploy Common Stack
126124
127-
5. Deploy Allora Worker Node
125+
```bash
126+
pwd
127+
# Make sure you are in aws-blockchain-node-runners/lib/allora
128+
npx cdk deploy allora-common
129+
```
128130
129-
```bash
130-
pwd
131-
# Make sure you are in aws-blockchain-node-runners/lib/allora
132-
npx cdk deploy allora-single-node --json --outputs-file single-node-deploy.json
133-
```
131+
4. Deploy Allora Worker Node
134132

135-
## Clear up and undeploy everything
133+
```bash
134+
pwd
135+
# Make sure you are in aws-blockchain-node-runners/lib/allora
136+
npx cdk deploy allora-single-node --json --outputs-file single-node-deploy.json
137+
```
136138

137-
1. Undeploy worker node and common components
139+
5. Test your node
138140

139-
```bash
140-
# Setting the AWS account id and region in case local .env file is lost
141-
export AWS_ACCOUNT_ID=<your_target_AWS_account_id>
142-
export AWS_REGION=<your_target_AWS_region>
141+
```bash
142+
INSTANCE_ID=$(cat single-node-deploy.json | jq -r '..|.nodeinstanceid? | select(. != null)')
143+
NODE_INTERNAL_IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query 'Reservations[*].Instances[*].PrivateIpAddress' --output text)
144+
echo "NODE_INTERNAL_IP=$NODE_INTERNAL_IP"
145+
TOKEN="ETH"
143146

144-
pwd
145-
# Make sure you are in aws-blockchain-node-runners/lib/allora
147+
curl http://$NODE_INTERNAL_IP:8000/inference/$TOKEN
148+
```
146149

147-
# Undeploy Single Node
148-
npx cdk destroy allora-single-node
150+
## Clear up and undeploy everything
149151

150-
# Undeploy Common Stack
151-
npx cdk destroy allora-edge-nodes-common
152-
```
152+
1. Undeploy worker node and common components
153153

154-
2. Follow these steps to delete the Cloud9 instance in [Cloud9 Setup](../../docs/setup-cloud9.md)
154+
```bash
155+
# Setting the AWS account id and region in case local .env file is lost
156+
export AWS_ACCOUNT_ID=<your_target_AWS_account_id>
157+
export AWS_REGION=<your_target_AWS_region>
155158

156-
Navigate to the AWS Cloud9 service in your Management Console, then select the environment you have created. On the top right, click **Delete** button and follow the instructions.
159+
pwd
160+
# Make sure you are in aws-blockchain-node-runners/lib/allora
157161

158-
3. Delete the instance profile and IAM role
162+
# Undeploy Single Node
163+
npx cdk destroy allora-single-node
159164

160-
```bash
161-
aws iam delete-instance-profile --instance-profile-name Cloud9-Developer-Access
162-
aws iam delete-role --role-name Cloud9-Developer-Access
165+
# Undeploy Common Stack
166+
npx cdk destroy allora-common
163167
```
164168

165169
### FAQ

lib/allora/allora.ts

Lines changed: 0 additions & 92 deletions
This file was deleted.

lib/allora/app.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env node
2+
import 'dotenv/config';
3+
import 'source-map-support/register';
4+
import * as cdk from 'aws-cdk-lib';
5+
import { AlloraCommonStack } from "./lib/common-stack";
6+
import { AlloraStack } from './lib/single-node-stack';
7+
import { baseConfig, singleNodeConfig } from './lib/config/node-config';
8+
9+
const app = new cdk.App();
10+
11+
new AlloraCommonStack(app, "allora-common", {
12+
stackName: `allora-common`,
13+
env: { account: baseConfig.accountId, region: baseConfig.region },
14+
});
15+
16+
new AlloraStack(app, 'allora-single-node', {
17+
stackName: 'allora-single-node',
18+
env: {
19+
account: baseConfig.accountId,
20+
region: baseConfig.region
21+
},
22+
...singleNodeConfig
23+
});

lib/allora/cdk.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"app": "npx ts-node --prefer-ts-exts allora.ts",
2+
"app": "npx ts-node --prefer-ts-exts app.ts",
33
"watch": {
44
"include": [
55
"**"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[cfn-auto-reloader-hook]
2+
triggers=post.update
3+
path=Resources.WebServerHost.Metadata.AWS::CloudFormation::Init
4+
action=/opt/aws/bin/cfn-init -v --stack __AWS_STACK_NAME__ --resource WebServerHost --region __AWS_REGION__
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[main]
2+
stack=__AWS_STACK_ID__
3+
region=__AWS_REGION__
4+
# The interval used to check for changes to the resource metadata in minutes. Default is 15
5+
interval=2
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[Unit]
2+
Description=cfn-hup daemon
3+
[Service]
4+
Type=simple
5+
ExecStart=/usr/local/bin/cfn-hup
6+
Restart=always
7+
[Install]
8+
WantedBy=multi-user.target
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
if [ -n "$1" ]; then
4+
export STACK_ID=$1
5+
else
6+
echo "Error: No Stack ID is provided"
7+
echo "Usage: instance/cfn-hup/setup.sh <stack_id> <aws_region>"
8+
exit 1
9+
fi
10+
11+
if [ -n "$2" ]; then
12+
export AWS_REGION=$2
13+
else
14+
echo "Error: No AWS Region is provided"
15+
echo "Usage: instance/cfn-hup/setup.sh <stack_id> <aws_region>"
16+
exit 1
17+
fi
18+
19+
echo "Install CloudFormation helper scripts"
20+
mkdir -p /opt/aws/
21+
pip3 install --break-system-packages https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz
22+
ln -s /usr/local/init/ubuntu/cfn-hup /etc/init.d/cfn-hup
23+
24+
echo "Configuring CloudFormation helper scripts"
25+
mkdir -p /etc/cfn/
26+
mv /opt/instance/cfn-hup/cfn-hup.conf /etc/cfn/cfn-hup.conf
27+
sed -i "s;__AWS_STACK_ID__;\"$STACK_ID\";g" /etc/cfn/cfn-hup.conf
28+
sed -i "s;__AWS_REGION__;\"$AWS_REGION\";g" /etc/cfn/cfn-hup.conf
29+
30+
mkdir -p /etc/cfn/hooks.d/system
31+
mv /opt/instance/cfn-hup/cfn-auto-reloader.conf /etc/cfn/hooks.d/cfn-auto-reloader.conf
32+
sed -i "s;__AWS_STACK_NAME__;\"$STACK_NAME\";g" /etc/cfn/hooks.d/cfn-auto-reloader.conf
33+
sed -i "s;__AWS_REGION__;\"$AWS_REGION\";g" /etc/cfn/hooks.d/cfn-auto-reloader.conf
34+
35+
echo "Starting CloudFormation helper scripts as a service"
36+
mv /opt/instance/cfn-hup/cfn-hup.service /etc/systemd/system/cfn-hup.service
37+
38+
systemctl daemon-reload
39+
systemctl enable --now cfn-hup
40+
systemctl start cfn-hup.service
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
source /etc/cdk_environment
4+
TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
5+
INSTANCE_ID=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s http://169.254.169.254/latest/meta-data/instance-id)
6+
7+
echo "Sync started at " $(date)
8+
SECONDS=0
9+
10+
s5cmd --log error cp --exclude 'lost+found' $SNAPSHOT_S3_PATH/data/* /data && \
11+
chown -R bcuser:bcuser /data && \
12+
echo "Sync finished at " $(date) && \
13+
echo "$(($SECONDS / 60)) minutes and $(($SECONDS % 60)) seconds elapsed." && \
14+
su bcuser && \
15+
docker compose -f /home/bcuser/docker-compose.yml up -d && \
16+
aws autoscaling complete-lifecycle-action --lifecycle-action-result CONTINUE --instance-id $INSTANCE_ID --lifecycle-hook-name "$LIFECYCLE_HOOK_NAME" --auto-scaling-group-name "$AUTOSCALING_GROUP_NAME" --region $REGION || \
17+
aws autoscaling complete-lifecycle-action --lifecycle-action-result ABANDON --instance-id $INSTANCE_ID --lifecycle-hook-name "$LIFECYCLE_HOOK_NAME" --auto-scaling-group-name "$AUTOSCALING_GROUP_NAME" --region $REGION
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set +e
3+
source /etc/cdk_environment
4+
5+
/usr/local/bin/docker-compose -f /home/bcuser/docker-compose.yml down
6+
echo "Sync started at " $(date)
7+
s5cmd --log error sync /data $SNAPSHOT_S3_PATH/
8+
echo "Sync finished at " $(date)
9+
sudo touch /data/snapshotted
10+
sudo su bcuser
11+
docker compose -f /home/bcuser/docker-compose.yml up -d

0 commit comments

Comments
 (0)