|
@@ -0,0 +1,179 @@
|
|
|
+AWSTemplateFormatVersion: 2010-09-09
|
|
|
+
|
|
|
+Parameters:
|
|
|
+ EC2InstanceType:
|
|
|
+ Type: String
|
|
|
+ EC2AMI:
|
|
|
+ Type: String
|
|
|
+ Default: 'ami-09e67e426f25ce0d7'
|
|
|
+ DefaultAMI:
|
|
|
+ Type: String
|
|
|
+ Default: 'ami-09e67e426f25ce0d7'
|
|
|
+ KeyName:
|
|
|
+ Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
|
|
|
+ Type: 'AWS::EC2::KeyPair::KeyName'
|
|
|
+ Default: 'joystream-key'
|
|
|
+ ConstraintDescription: must be the name of an existing EC2 KeyPair.
|
|
|
+
|
|
|
+Conditions:
|
|
|
+ HasAMIId: !Not [!Equals [!Ref EC2AMI, ""]]
|
|
|
+
|
|
|
+Resources:
|
|
|
+ SecurityGroup:
|
|
|
+ Type: AWS::EC2::SecurityGroup
|
|
|
+ Properties:
|
|
|
+ GroupDescription:
|
|
|
+ !Sub 'Internal Security group for validator nodes ${AWS::StackName}'
|
|
|
+ SecurityGroupIngress:
|
|
|
+ - IpProtocol: tcp
|
|
|
+ FromPort: 30333
|
|
|
+ ToPort: 30333
|
|
|
+ CidrIp: 0.0.0.0/0
|
|
|
+ - IpProtocol: tcp
|
|
|
+ FromPort: 22
|
|
|
+ ToPort: 22
|
|
|
+ CidrIp: 0.0.0.0/0
|
|
|
+ Tags:
|
|
|
+ - Key: Name
|
|
|
+ Value: !Sub '${AWS::StackName}_validator'
|
|
|
+
|
|
|
+ RPCSecurityGroup:
|
|
|
+ Type: AWS::EC2::SecurityGroup
|
|
|
+ Properties:
|
|
|
+ GroupDescription:
|
|
|
+ !Sub 'Internal Security group for RPC nodes ${AWS::StackName}'
|
|
|
+ SecurityGroupIngress:
|
|
|
+ - IpProtocol: tcp
|
|
|
+ FromPort: 9933
|
|
|
+ ToPort: 9933
|
|
|
+ CidrIp: 0.0.0.0/0
|
|
|
+ - IpProtocol: tcp
|
|
|
+ FromPort: 9944
|
|
|
+ ToPort: 9944
|
|
|
+ CidrIp: 0.0.0.0/0
|
|
|
+ - IpProtocol: tcp
|
|
|
+ FromPort: 22
|
|
|
+ ToPort: 22
|
|
|
+ CidrIp: 0.0.0.0/0
|
|
|
+ Tags:
|
|
|
+ - Key: Name
|
|
|
+ Value: !Sub '${AWS::StackName}_rpc'
|
|
|
+
|
|
|
+ InstanceLaunchTemplate:
|
|
|
+ Type: AWS::EC2::LaunchTemplate
|
|
|
+ Metadata:
|
|
|
+ AWS::CloudFormation::Init:
|
|
|
+ config:
|
|
|
+ packages:
|
|
|
+ apt:
|
|
|
+ wget: []
|
|
|
+ unzip: []
|
|
|
+ Properties:
|
|
|
+ LaunchTemplateName: !Sub 'LaunchTemplate_${AWS::StackName}'
|
|
|
+ LaunchTemplateData:
|
|
|
+ ImageId: !If [HasAMIId, !Ref EC2AMI, !Ref DefaultAMI]
|
|
|
+ InstanceType: !Ref EC2InstanceType
|
|
|
+ KeyName: !Ref KeyName
|
|
|
+ SecurityGroupIds:
|
|
|
+ - !GetAtt SecurityGroup.GroupId
|
|
|
+ BlockDeviceMappings:
|
|
|
+ - DeviceName: /dev/sda1
|
|
|
+ Ebs:
|
|
|
+ VolumeSize: '40'
|
|
|
+ UserData:
|
|
|
+ Fn::Base64: !Sub |
|
|
|
+ #!/bin/bash -xe
|
|
|
+
|
|
|
+ # send script output to /tmp so we can debug boot failures
|
|
|
+ exec > /tmp/userdata.log 2>&1
|
|
|
+
|
|
|
+ # Update all packages
|
|
|
+ apt-get update -y
|
|
|
+
|
|
|
+ # Install the updates
|
|
|
+ apt-get upgrade -y
|
|
|
+
|
|
|
+ # Get latest cfn scripts and install them;
|
|
|
+ apt-get install -y python3-setuptools
|
|
|
+ mkdir -p /opt/aws/bin
|
|
|
+ wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz
|
|
|
+ python3 -m easy_install --script-dir /opt/aws/bin aws-cfn-bootstrap-py3-latest.tar.gz
|
|
|
+
|
|
|
+ /opt/aws/bin/cfn-signal -e $? -r "Instance Created" '${WaitHandle}'
|
|
|
+
|
|
|
+ Instance:
|
|
|
+ Type: AWS::EC2::Instance
|
|
|
+ Properties:
|
|
|
+ LaunchTemplate:
|
|
|
+ LaunchTemplateId: !Ref InstanceLaunchTemplate
|
|
|
+ Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber
|
|
|
+ Tags:
|
|
|
+ - Key: Name
|
|
|
+ Value: !Sub '${AWS::StackName}_1'
|
|
|
+
|
|
|
+ Instance2:
|
|
|
+ Type: AWS::EC2::Instance
|
|
|
+ Properties:
|
|
|
+ LaunchTemplate:
|
|
|
+ LaunchTemplateId: !Ref InstanceLaunchTemplate
|
|
|
+ Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber
|
|
|
+ Tags:
|
|
|
+ - Key: Name
|
|
|
+ Value: !Sub '${AWS::StackName}_2'
|
|
|
+
|
|
|
+ RPCInstance:
|
|
|
+ Type: AWS::EC2::Instance
|
|
|
+ Properties:
|
|
|
+ SecurityGroupIds:
|
|
|
+ - !GetAtt RPCSecurityGroup.GroupId
|
|
|
+ LaunchTemplate:
|
|
|
+ LaunchTemplateId: !Ref InstanceLaunchTemplate
|
|
|
+ Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber
|
|
|
+ Tags:
|
|
|
+ - Key: Name
|
|
|
+ Value: !Sub '${AWS::StackName}_rpc'
|
|
|
+
|
|
|
+ BuildInstance:
|
|
|
+ Type: AWS::EC2::Instance
|
|
|
+ Properties:
|
|
|
+ LaunchTemplate:
|
|
|
+ LaunchTemplateId: !Ref InstanceLaunchTemplate
|
|
|
+ Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber
|
|
|
+ Tags:
|
|
|
+ - Key: Name
|
|
|
+ Value: !Sub '${AWS::StackName}_build'
|
|
|
+
|
|
|
+ WaitHandle:
|
|
|
+ Type: AWS::CloudFormation::WaitConditionHandle
|
|
|
+
|
|
|
+ WaitCondition:
|
|
|
+ Type: AWS::CloudFormation::WaitCondition
|
|
|
+ Properties:
|
|
|
+ Handle: !Ref 'WaitHandle'
|
|
|
+ Timeout: '600'
|
|
|
+ Count: 4
|
|
|
+
|
|
|
+Outputs:
|
|
|
+ PublicIp:
|
|
|
+ Description: The DNS name for the created instance
|
|
|
+ Value: !Sub "${Instance.PublicIp}"
|
|
|
+ Export:
|
|
|
+ Name: !Sub "${AWS::StackName}PublicIp"
|
|
|
+
|
|
|
+ PublicIp2:
|
|
|
+ Description: The DNS name for the created instance
|
|
|
+ Value: !Sub "${Instance2.PublicIp}"
|
|
|
+ Export:
|
|
|
+ Name: !Sub "${AWS::StackName}PublicIp2"
|
|
|
+
|
|
|
+ RPCPublicIp:
|
|
|
+ Description: The DNS name for the created instance
|
|
|
+ Value: !Sub "${RPCInstance.PublicIp}"
|
|
|
+ Export:
|
|
|
+ Name: !Sub "${AWS::StackName}RPCPublicIp"
|
|
|
+
|
|
|
+ BuildPublicIp:
|
|
|
+ Description: The DNS name for the created instance
|
|
|
+ Value: !Sub "${BuildInstance.PublicIp}"
|
|
|
+ Export:
|
|
|
+ Name: !Sub "${AWS::StackName}BuildPublicIp"
|