single-instance.yml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. AWSTemplateFormatVersion: 2010-09-09
  2. Parameters:
  3. EC2InstanceType:
  4. Type: String
  5. Default: t2.xlarge
  6. EC2AMI:
  7. Type: String
  8. Default: 'ami-09e67e426f25ce0d7'
  9. DefaultAMI:
  10. Type: String
  11. Default: 'ami-09e67e426f25ce0d7'
  12. KeyName:
  13. Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
  14. Type: 'AWS::EC2::KeyPair::KeyName'
  15. Default: 'joystream-key'
  16. ConstraintDescription: must be the name of an existing EC2 KeyPair.
  17. Conditions:
  18. HasAMIId: !Not [!Equals [!Ref EC2AMI, ""]]
  19. Resources:
  20. SecurityGroup:
  21. Type: AWS::EC2::SecurityGroup
  22. Properties:
  23. GroupDescription:
  24. !Sub 'Internal Security group for validator nodes ${AWS::StackName}'
  25. SecurityGroupIngress:
  26. - IpProtocol: tcp
  27. FromPort: 22
  28. ToPort: 22
  29. CidrIp: 0.0.0.0/0
  30. Tags:
  31. - Key: Name
  32. Value: !Sub '${AWS::StackName}_validator'
  33. InstanceLaunchTemplate:
  34. Type: AWS::EC2::LaunchTemplate
  35. Metadata:
  36. AWS::CloudFormation::Init:
  37. config:
  38. packages:
  39. apt:
  40. wget: []
  41. unzip: []
  42. Properties:
  43. LaunchTemplateName: !Sub 'LaunchTemplate_${AWS::StackName}'
  44. LaunchTemplateData:
  45. ImageId: !If [HasAMIId, !Ref EC2AMI, !Ref DefaultAMI]
  46. InstanceType: !Ref EC2InstanceType
  47. KeyName: !Ref KeyName
  48. SecurityGroupIds:
  49. - !GetAtt SecurityGroup.GroupId
  50. BlockDeviceMappings:
  51. - DeviceName: /dev/sda1
  52. Ebs:
  53. VolumeSize: '30'
  54. UserData:
  55. Fn::Base64: !Sub |
  56. #!/bin/bash -xe
  57. # send script output to /tmp so we can debug boot failures
  58. exec > /tmp/userdata.log 2>&1
  59. # Update all packages
  60. apt-get update -y
  61. # Install the updates
  62. apt-get upgrade -y
  63. # Get latest cfn scripts and install them;
  64. apt-get install -y python3-setuptools
  65. mkdir -p /opt/aws/bin
  66. wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz
  67. python3 -m easy_install --script-dir /opt/aws/bin aws-cfn-bootstrap-py3-latest.tar.gz
  68. /opt/aws/bin/cfn-signal -e $? -r "Instance Created" '${WaitHandle}'
  69. Instance:
  70. Type: AWS::EC2::Instance
  71. Properties:
  72. LaunchTemplate:
  73. LaunchTemplateId: !Ref InstanceLaunchTemplate
  74. Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber
  75. Tags:
  76. - Key: Name
  77. Value: !Sub '${AWS::StackName}_1'
  78. WaitHandle:
  79. Type: AWS::CloudFormation::WaitConditionHandle
  80. WaitCondition:
  81. Type: AWS::CloudFormation::WaitCondition
  82. Properties:
  83. Handle: !Ref 'WaitHandle'
  84. Timeout: '600'
  85. Count: 1
  86. Outputs:
  87. PublicIp:
  88. Description: The DNS name for the created instance
  89. Value: !Sub "${Instance.PublicIp}"
  90. InstanceId:
  91. Description: The Instance ID
  92. Value: !Ref Instance