single-instance.yml 2.9 KB

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