single-instance.yml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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: '30'
  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. # Install the updates
  57. apt-get upgrade -y
  58. # Get latest cfn scripts and install them;
  59. apt-get install -y python3-setuptools
  60. mkdir -p /opt/aws/bin
  61. wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz
  62. python3 -m easy_install --script-dir /opt/aws/bin aws-cfn-bootstrap-py3-latest.tar.gz
  63. /opt/aws/bin/cfn-signal -e $? -r "Instance Created" '${WaitHandle}'
  64. Instance:
  65. Type: AWS::EC2::Instance
  66. Properties:
  67. LaunchTemplate:
  68. LaunchTemplateId: !Ref InstanceLaunchTemplate
  69. Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber
  70. Tags:
  71. - Key: Name
  72. Value: !Sub '${AWS::StackName}_1'
  73. WaitHandle:
  74. Type: AWS::CloudFormation::WaitConditionHandle
  75. WaitCondition:
  76. Type: AWS::CloudFormation::WaitCondition
  77. Properties:
  78. Handle: !Ref 'WaitHandle'
  79. Timeout: '600'
  80. Count: 1
  81. Outputs:
  82. PublicIp:
  83. Description: The DNS name for the created instance
  84. Value: !Sub "${Instance.PublicIp}"
  85. Export:
  86. Name: !Sub "${AWS::StackName}PublicIp"
  87. InstanceId:
  88. Description: The Instance ID
  89. Value: !Ref Instance