Skip to content

Commit d14cd27

Browse files
authored
Merge pull request #26 from aws-samples/scroll
Add a new blueprint for Scroll Single-node deployment
2 parents 6c71f85 + ff61c18 commit d14cd27

39 files changed

+2869
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ ha-nodes-deploy*.json
3434

3535
*.OLD
3636
.env
37+
.idea

docs/adding-new-nodes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ First of all, THANK YOU! The easier it is to run a blockchain node on AWS the si
3131
- `lib/constructs/constants.ts` - Useful constants to use in configuration files and to set up infrastructure.
3232
- `lib/constructs/ha-rpc-nodes-with-alb.ts` - Provisions up to 4 identical EC2 instances to run nodes managed by an Auto Scaling Group and behind an Application Load Balancer.
3333
- `lib/constructs/single-node.ts` - Creates a single EC2 instance to run a blockchain node.
34-
- `lib/constructs/snapshots-bucket.ts` - Creates an S3 bucket to store a copy of blockchain node state to speed up syncing process.
34+
- `lib/constructs/snapshots-bucket.ts` - Creates an S3 bucket to store a copy of blockchain node state to speed up syncing process.

docs/pre-merge-tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ npm run install-pre-commit-mac
4040

4141
# Run
4242
npm run run-pre-commit
43-
```
43+
```
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import * as cdk from "aws-cdk-lib";
2+
import * as cdkContructs from 'constructs';
3+
import * as cr from 'aws-cdk-lib/custom-resources';
4+
import * as configTypes from "./config.interface";
5+
import * as nag from "cdk-nag";
6+
7+
export interface SingleNodeAMBEthereumConstructCustomProps {
8+
instanceType: string,
9+
availabilityZone: string,
10+
ethNetworkId: configTypes.AMBEthereumNodeNetworkId,
11+
}
12+
13+
export class SingleNodeAMBEthereumConstruct extends cdkContructs.Construct {
14+
public nodeId: string;
15+
public rpcUrl: string;
16+
public billingToken: string;
17+
public rpcUrlWithBillingToken: string;
18+
19+
20+
constructor(scope: cdkContructs.Construct, id: string, props: SingleNodeAMBEthereumConstructCustomProps) {
21+
super(scope, id);
22+
23+
const REGION = cdk.Stack.of(this).region;
24+
const {
25+
instanceType,
26+
availabilityZone,
27+
ethNetworkId,
28+
} = props;
29+
30+
const createNode = new cr.AwsCustomResource(this, 'createNode', {
31+
onCreate: { // will be called for a CREATE event
32+
service: 'ManagedBlockchain',
33+
action: 'createNode',
34+
parameters: {
35+
NetworkId: `n-ethereum-${ethNetworkId}`,
36+
NodeConfiguration: {
37+
AvailabilityZone: availabilityZone,
38+
InstanceType: instanceType
39+
}
40+
},
41+
physicalResourceId: cr.PhysicalResourceId.of(Date.now().toString()), // Update physical id to always fetch the latest version
42+
},
43+
installLatestAwsSdk:true,
44+
policy: cr.AwsCustomResourcePolicy.fromSdkCalls({
45+
resources: cr.AwsCustomResourcePolicy.ANY_RESOURCE,
46+
}),
47+
});
48+
49+
const createAccessor = new cr.AwsCustomResource(this, 'createAccessor', {
50+
onCreate: { // will be called for a CREATE event
51+
service: 'ManagedBlockchain',
52+
action: 'createAccessor',
53+
parameters: {
54+
AccessorType: 'BILLING_TOKEN'
55+
},
56+
physicalResourceId: cr.PhysicalResourceId.of(Date.now().toString()), // Update physical id to always fetch the latest version
57+
},
58+
installLatestAwsSdk:true,
59+
policy: cr.AwsCustomResourcePolicy.fromSdkCalls({
60+
resources: cr.AwsCustomResourcePolicy.ANY_RESOURCE,
61+
}),
62+
});
63+
64+
this.nodeId = createNode.getResponseField('NodeId');
65+
this.rpcUrl = `https://${this.nodeId}.t.ethereum.managedblockchain.${REGION}.amazonaws.com`;
66+
this.billingToken=createAccessor.getResponseField('BillingToken');
67+
this.rpcUrlWithBillingToken = `${this.rpcUrl}?billingtoken=${this.billingToken}`;
68+
69+
const deleteAccessor = new cr.AwsCustomResource(this, 'deleteAccessor', {
70+
onDelete: {
71+
service: 'ManagedBlockchain',
72+
action: 'deleteAccessor',
73+
parameters: {
74+
AccessorId: createAccessor.getResponseField('AccessorId'),
75+
},
76+
},
77+
installLatestAwsSdk:true,
78+
policy: cr.AwsCustomResourcePolicy.fromSdkCalls({
79+
resources: cr.AwsCustomResourcePolicy.ANY_RESOURCE,
80+
}),
81+
});
82+
83+
const deleteNode = new cr.AwsCustomResource(this, 'deleteNode', {
84+
onDelete: {
85+
service: 'ManagedBlockchain',
86+
action: 'deleteNode',
87+
parameters: {
88+
NetworkId: `n-ethereum-${ethNetworkId}`,
89+
NodeId: this.nodeId,
90+
},
91+
},
92+
installLatestAwsSdk:true,
93+
policy: cr.AwsCustomResourcePolicy.fromSdkCalls({
94+
resources: cr.AwsCustomResourcePolicy.ANY_RESOURCE,
95+
}),
96+
});
97+
98+
// nag.NagSuppressions.addResourceSuppressions(
99+
// this,
100+
// [
101+
// {
102+
// id: "AwsSolutions-EC29",
103+
// reason: "Its Ok to terminate this instance as long as we have the data in the snapshot",
104+
105+
// },
106+
// ],
107+
// true
108+
// );
109+
}
110+
}

lib/constructs/config.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ export interface HaNodesConfig extends BaseNodeConfig {
2828
numberOfNodes: number;
2929
dataVolumes: DataVolumeConfig[];
3030
}
31+
32+
export type AMBEthereumNodeNetworkId = "mainnet" | "goerli";

lib/scroll/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*.js
2+
!jest.config.js
3+
*.d.ts
4+
node_modules
5+
6+
# CDK asset staging directory
7+
.cdk.staging
8+
cdk.out
9+
.idea
10+
11+
*-node.json

lib/scroll/.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.ts
2+
!*.d.ts
3+
4+
# CDK asset staging directory
5+
.cdk.staging
6+
cdk.out

0 commit comments

Comments
 (0)