Skip to content

Commit c221022

Browse files
committed
user-data still freezing the instance
1 parent 9dce197 commit c221022

File tree

5 files changed

+113
-40
lines changed

5 files changed

+113
-40
lines changed

lib/allora/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,15 @@ We will use AWS Cloud9 to execute the subsequent commands. Follow the instructio
9090
> cdk bootstrap aws://ACCOUNT-NUMBER/REGION
9191
> ```
9292
93-
3. Deploy Allora Worker Node
93+
3. Deploy Common Stack
94+
95+
```bash
96+
pwd
97+
# Make sure you are in aws-blockchain-node-runners/lib/allora
98+
npx cdk deploy allora-edge-common --json --outputs-file allora-edge-common-deploy.json
99+
```
100+
101+
5. Deploy Allora Worker Node
94102
95103
```bash
96104
pwd

lib/allora/allora.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'source-map-support/register';
44
import * as cdk from 'aws-cdk-lib';
55
import * as ec2 from "aws-cdk-lib/aws-ec2";
66
import * as constants from "../constructs/constants";
7+
import { EdgeCommonStack } from "./lib/common-stack";
78
import { AlloraStack } from './lib/allora-stack';
89

910
const parseDataVolumeType = (dataVolumeType: string) => {
@@ -22,6 +23,12 @@ const parseDataVolumeType = (dataVolumeType: string) => {
2223
};
2324

2425
const app = new cdk.App();
26+
27+
new EdgeCommonStack(app, "allora-edge-common", {
28+
stackName: `allora-edge-nodes-common`,
29+
env: { account: process.env.AWS_ACCOUNT_ID || "xxxxxxxxxxx", region: process.env.AWS_REGION || 'us-east-1' }
30+
});
31+
2532
new AlloraStack(app, 'allora-single-node', {
2633
stackName: 'allora-single-node',
2734
env: {

lib/allora/lib/allora-stack.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ export class AlloraStack extends cdk.Stack {
5555

5656
// Create VPC
5757
const vpc = new ec2.Vpc(this, `${resourceNamePrefix}Vpc`, {
58-
maxAzs: props?.vpcMaxAzs || 1,
59-
natGateways: typeof props?.vpcNatGateways !== 'undefined' ? props?.vpcNatGateways : 0,
58+
maxAzs: props.vpcMaxAzs,
59+
natGateways: props.vpcNatGateways,
6060
subnetConfiguration: [{
61-
cidrMask: props?.vpcSubnetCidrMask || 24,
61+
cidrMask: props.vpcSubnetCidrMask,
6262
name:`${resourceNamePrefix}PublicSubnet`,
6363
subnetType: ec2.SubnetType.PUBLIC,
6464
}]
@@ -84,26 +84,11 @@ export class AlloraStack extends cdk.Stack {
8484
const ec2UserData = ec2.UserData.forLinux();
8585
ec2UserData.addCommands(modifiedUserData);
8686

87-
// Getting the snapshot bucket name and IAM role ARN from the common stack
88-
const instanceRole = new iam.Role(this, "node-role", {
89-
assumedBy: new iam.ServicePrincipal("ec2.amazonaws.com"),
90-
managedPolicies: [
91-
iam.ManagedPolicy.fromAwsManagedPolicyName("AmazonSSMManagedInstanceCore"),
92-
iam.ManagedPolicy.fromAwsManagedPolicyName("CloudWatchAgentServerPolicy")
93-
94-
]
95-
});
96-
97-
instanceRole.addToPolicy(new iam.PolicyStatement({
98-
resources: ["*"],
99-
actions: ["cloudformation:SignalResource"]
100-
}));
10187

88+
// Getting the snapshot bucket name and IAM role ARN from the common stack
89+
const importedInstanceRoleArn = cdk.Fn.importValue("EdgeNodeInstanceRoleArn");
10290

103-
new cdk.CfnOutput(this, "Instance Role ARN", {
104-
value: instanceRole.roleArn,
105-
exportName: "EdgeNodeInstanceRoleArn"
106-
});
91+
const instanceRole = iam.Role.fromRoleArn(this, "iam-role", importedInstanceRoleArn);
10792

10893
// Making sure our instance will be able to read the assets
10994
bucket.grantRead(instanceRole);
@@ -134,12 +119,16 @@ export class AlloraStack extends cdk.Stack {
134119
INSTANCE_ID: singleNode.instanceId,
135120
INSTANCE_NAME: `${resourceNamePrefix}Instance`,
136121
REGION: region,
137-
})
122+
});
138123

139-
new cw.CfnDashboard(this, 'single-cw-dashboard', {
124+
new cw.CfnDashboard(this, 'single-cw-dashboard', {
140125
dashboardName: `AlloraStack-${singleNode.instanceId}`,
141126
dashboardBody: dashboardString,
142-
});
127+
});
128+
129+
new cdk.CfnOutput(this, "node-instance-id", {
130+
value: singleNode.instanceId,
131+
});
143132

144133
// Elastic IP
145134
const eip = new ec2.CfnEIP(this, `${resourceNamePrefix}EIP`);
Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/bash
2+
echo "----------------------------------------------"
3+
echo "[user-data] STARTING ALLORA USER DATA SCRIPT"
4+
echo "----------------------------------------------"
25

36
echo "AWS_REGION=${_AWS_REGION_}" >> /etc/environment
47
echo "ASSETS_S3_PATH=${_ASSETS_S3_PATH_}" >> /etc/environment
@@ -13,37 +16,41 @@ echo "ASSETS_S3_PATH=${_ASSETS_S3_PATH_}" >> /etc/environment
1316
#############################
1417

1518
# Update Ubuntu, answer yes to all prompts non-interactively
16-
sudo apt update --yes
19+
echo "[user-data] Update Ubuntu package list"
20+
sudo apt-get update --yes
1721

1822
# Install pip
19-
sudo apt install python3-pip --yes
23+
echo "[user-data] Install Pip"
24+
sudo apt-get install python3-pip --yes
2025

2126
# Install Pipx
22-
sudo apt install pipx --yes
27+
echo "[user-data] Install Pipx"
28+
sudo apt-get install pipx --yes
2329

2430
# Install Go
25-
sudo apt install golang-go --yes
26-
27-
28-
31+
echo "[user-data] Install Go"
32+
sudo apt-get install golang-go --yes
2933

3034
# Install Docker Compose
3135
# Install ca-certificates, a certificate authority package for verifying third-party identities, and curl, a data transfer tool:
32-
sudo apt install ca-certificates curl
36+
echo "[user-data] Install ca-certificates"
37+
sudo apt-get install ca-certificates --yes
38+
39+
echo "[user-data] Install curl"
40+
sudo apt-get install curl --yes
3341

3442
# Set ownership permissions for the /etc/apt/keyrings directory:
43+
echo "[user-data] Set ownership perms for /etc/apt/keyrings"
3544
sudo install -m 0755 -d /etc/apt/keyrings
3645

3746
# Download the key with curl:
47+
echo "[user-data] Downloading key with curl"
3848
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
3949

4050
# Set read permissions for the key:
51+
echo "[user-data] set read permissions for key"
4152
sudo chmod a+r /etc/apt/keyrings/docker.asc
4253

43-
44-
45-
46-
4754

4855
# Add the Docker repository to the list of APT sources:
4956
echo \
@@ -52,19 +59,27 @@ echo \
5259
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
5360

5461
# Install Docker Compose:
55-
sudo apt install docker-compose-plugin -y
62+
echo "[user-data] Install docker compose"
63+
sudo apt-get install docker-compose-plugin --yes
5664

5765
# Install Docker.io
58-
sudo apt install docker.io
66+
echo "[user-data] Install docker.io"
67+
sudo apt-get install docker.io --yes
5968

6069
# After the download completes, confirm that Docker Compose is installed by typing:
70+
echo "[user-data] run docker compose version"
6171
docker compose version
6272

73+
echo "[user-data] docker group and usermod"
6374
# Create the docker group if it does not already exist:
6475
sudo groupadd -f docker
6576
# Add the current user to the docker group via the usermod command:
6677
sudo usermod -aG docker $USER
78+
6779
# Start docker service
80+
echo "[user-data] Starting docker service"
6881
sudo service docker start
6982

70-
echo "Allora user-data script successful"
83+
echo "----------------------------------------------"
84+
echo "[user-data] Allora user-data script successful"
85+
echo "----------------------------------------------"

lib/allora/lib/common-stack.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import * as cdk from "aws-cdk-lib";
2+
import * as cdkConstructs from "constructs";
3+
import * as iam from "aws-cdk-lib/aws-iam";
4+
import * as secrets from "aws-cdk-lib/aws-secretsmanager";
5+
import * as nag from "cdk-nag";
6+
7+
export interface EdgeCommonStackProps extends cdk.StackProps {
8+
9+
}
10+
11+
export class EdgeCommonStack extends cdk.Stack {
12+
AWS_STACK_NAME = cdk.Stack.of(this).stackName;
13+
AWS_ACCOUNT_ID = cdk.Stack.of(this).account;
14+
15+
constructor(scope: cdkConstructs.Construct, id: string, props: EdgeCommonStackProps) {
16+
super(scope, id, props);
17+
18+
const instanceRole = new iam.Role(this, "node-role", {
19+
assumedBy: new iam.ServicePrincipal("ec2.amazonaws.com"),
20+
managedPolicies: [
21+
iam.ManagedPolicy.fromAwsManagedPolicyName("AmazonSSMManagedInstanceCore"),
22+
iam.ManagedPolicy.fromAwsManagedPolicyName("CloudWatchAgentServerPolicy")
23+
24+
]
25+
});
26+
27+
instanceRole.addToPolicy(new iam.PolicyStatement({
28+
resources: ["*"],
29+
actions: ["cloudformation:SignalResource"]
30+
}));
31+
32+
33+
new cdk.CfnOutput(this, "Instance Role ARN", {
34+
value: instanceRole.roleArn,
35+
exportName: "EdgeNodeInstanceRoleArn"
36+
});
37+
38+
// cdk-nag suppressions
39+
nag.NagSuppressions.addResourceSuppressions(
40+
this,
41+
[
42+
{
43+
id: "AwsSolutions-IAM4",
44+
reason: "AmazonSSMManagedInstanceCore and CloudWatchAgentServerPolicy are restrictive enough"
45+
},
46+
{
47+
id: "AwsSolutions-IAM5",
48+
reason: "Can't target specific stack: https://github.com/aws/aws-cdk/issues/22657"
49+
}
50+
],
51+
true
52+
);
53+
}
54+
}

0 commit comments

Comments
 (0)