diff --git a/README.md b/README.md index 0eb7a7d..f0e3c78 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ You can use `lncli` to open channels, create invoices, do all the fun lightning By default, the grpc port will not be accessible. There's a security group that get's created for it, but isn't attached to the node. If you uncomment the line that says `// instance.addSecurityGroup(rpcSg);` and run `cdk deploy`, it'll attach that security group and you'll be able to get to the grpc ports. Want to close them up? comment that line out and do `cdk deploy` again and it'll detach the security group. +Want to add a second (or third or fourth) node? Go into `bin/thundercloud.ts` and add a line at the end like `new LightningNode(app, 'SecondLightningNode', {stackName: "SecondLightningNode"});`, then do `cdk deploy SecondLightningNode`. + ## Shutting down the node 1. go into the project root and do `cdk destroy` There is no step 2. You can also go find the stack in CloudFormation and delete it there. either way works. diff --git a/bin/thundercloud.ts b/bin/thundercloud.ts index 6176139..134f803 100644 --- a/bin/thundercloud.ts +++ b/bin/thundercloud.ts @@ -19,3 +19,6 @@ new LightningNode(app, 'ThundercloudStack', { /* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */ }); + +// Here's an example of a second node. uncomment this and then run `cdk deploy SecondLightningNode` +// new LightningNode(app, 'SecondLightningNode', {stackName: "SecondLightningNode"}); \ No newline at end of file diff --git a/lib/lightningnode-stack.ts b/lib/lightningnode-stack.ts index 7c421e2..3f4ca7f 100644 --- a/lib/lightningnode-stack.ts +++ b/lib/lightningnode-stack.ts @@ -14,40 +14,38 @@ export class LightningNode extends cdk.Stack { constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); + const suffix = props?.stackName || ""; // Set up a VPC with public and isolated subnets in 3 AZs (out of the list above) - const vpc = new ec2.Vpc(this, "vpc", { + const vpc = new ec2.Vpc(this, "vpc" + suffix, { cidr: "10.0.0.0/16", natGateways: 0, maxAzs: 3, }); // SSH key for the node - const key = new KeyPair(this, 'KeyPair', { + const key = new KeyPair(this, 'KeyPair' + suffix, { name: 'cdk-keypair', description: 'Key Pair created with CDK Deployment', }); // Security groups. I made three different ones because adding/removing SGs from instances // is easier to do through automation than changing rules on a single SG. - const sshSg = new ec2.SecurityGroup(this, 'sshSecurityGroup', { + const sshSg = new ec2.SecurityGroup(this, 'sshSecurityGroup' + suffix, { vpc, description: 'Allow SSH (TCP port 22) in', }); sshSg.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(22), 'Allow SSH Access') - const lightningSg = new ec2.SecurityGroup(this, "LightningSecurityGroup", { + const lightningSg = new ec2.SecurityGroup(this, "LightningSecurityGroup" + suffix, { vpc, description: 'Allow lightning protocol (port 9735) traffic from the Internet', }); lightningSg.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(9735)); - const setupScript = new Asset(this, "SetupScript", { - path: path.join(__dirname, 'configure-node.sh') - }); - const rpcSg = new ec2.SecurityGroup(this, "RpcSecurityGroup", { + const rpcSg = new ec2.SecurityGroup(this, "RpcSecurityGroup" + suffix, { vpc, description: 'Allow access to lnd grpc interface', }); rpcSg.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(10009)); - const restSg = new ec2.SecurityGroup(this, "RestSecurityGroup", { + const restSg = new ec2.SecurityGroup(this, "RestSecurityGroup" + suffix, { vpc: vpc, description: "Allow access to lnd REST ports" }); @@ -59,7 +57,7 @@ export class LightningNode extends cdk.Stack { cpuType: ec2.AmazonLinuxCpuType.ARM_64 }); - const instance = new ec2.Instance(this, "lightningNode", { + const instance = new ec2.Instance(this, "lightningNode" + suffix, { instanceType: new ec2.InstanceType("t4g.micro"), vpc: vpc, machineImage: ami, @@ -76,12 +74,15 @@ export class LightningNode extends cdk.Stack { // You can also edit the ingress rule above if you want a different port // instance.addSecurityGroup(restSg); - const eip = new CfnEIP(this, "NodeEIP", { + const eip = new CfnEIP(this, "NodeEIP" + suffix, { domain: "vpc", instanceId: instance.instanceId }); // Wire the bootstrap script into the instance userdata + const setupScript = new Asset(this, "SetupScript" + suffix, { + path: path.join(__dirname, 'configure-node.sh') + }); const localPath = instance.userData.addS3DownloadCommand({ bucket:setupScript.bucket, bucketKey:setupScript.s3ObjectKey,