main.yml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. AWSTemplateFormatVersion: 2010-09-09
  2. Parameters:
  3. EC2InstanceType:
  4. Type: String
  5. EC2AMI:
  6. Type: String
  7. Default: 'ami-09e67e426f25ce0d7'
  8. KeyName:
  9. Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
  10. Type: 'AWS::EC2::KeyPair::KeyName'
  11. Default: 'joystream-key'
  12. ConstraintDescription: must be the name of an existing EC2 KeyPair.
  13. Resources:
  14. SecurityGroup:
  15. Type: AWS::EC2::SecurityGroup
  16. Properties:
  17. GroupDescription:
  18. !Sub 'Internal Security group for ${AWS::StackName}'
  19. SecurityGroupIngress:
  20. - IpProtocol: tcp
  21. FromPort: 9933
  22. ToPort: 9933
  23. CidrIp: 0.0.0.0/0
  24. - IpProtocol: tcp
  25. FromPort: 9944
  26. ToPort: 9944
  27. CidrIp: 0.0.0.0/0
  28. - IpProtocol: tcp
  29. FromPort: 22
  30. ToPort: 22
  31. CidrIp: 0.0.0.0/0
  32. Tags:
  33. - Key: Name
  34. Value: !Ref AWS::StackName
  35. InstanceLaunchTemplate:
  36. Type: AWS::EC2::LaunchTemplate
  37. Metadata:
  38. AWS::CloudFormation::Init:
  39. config:
  40. packages:
  41. apt:
  42. wget: []
  43. unzip: []
  44. Properties:
  45. LaunchTemplateName: !Sub 'LaunchTemplate_${AWS::StackName}'
  46. LaunchTemplateData:
  47. ImageId: !Ref EC2AMI
  48. InstanceType: !Ref EC2InstanceType
  49. KeyName: !Ref KeyName
  50. SecurityGroupIds:
  51. - !GetAtt SecurityGroup.GroupId
  52. BlockDeviceMappings:
  53. - DeviceName: /dev/sda1
  54. Ebs:
  55. VolumeSize: '40'
  56. UserData:
  57. Fn::Base64: !Sub |
  58. #!/bin/bash -xe
  59. # send script output to /tmp so we can debug boot failures
  60. exec > /tmp/userdata.log 2>&1
  61. # Update all packages
  62. apt-get update -y
  63. # Get latest cfn scripts;
  64. # apt-get install -y python3-pip
  65. apt-get install -y python3-setuptools
  66. mkdir -p /opt/aws/bin
  67. # pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz
  68. wget https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz
  69. python3 -m easy_install --script-dir /opt/aws/bin aws-cfn-bootstrap-py3-latest.tar.gz
  70. # curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
  71. # echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
  72. # apt-get update -y
  73. # apt-get install -y yarn
  74. ln -s /root/aws-cfn-bootstrap-latest/init/ubuntu/cfn-hup /etc/init.d/cfn-hup
  75. Instance:
  76. Type: AWS::EC2::Instance
  77. Properties:
  78. LaunchTemplate:
  79. LaunchTemplateId: !Ref InstanceLaunchTemplate
  80. Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber
  81. Tags:
  82. - Key: Name
  83. Value: !Sub '${AWS::StackName}_1'
  84. Instance2:
  85. Type: AWS::EC2::Instance
  86. Properties:
  87. LaunchTemplate:
  88. LaunchTemplateId: !Ref InstanceLaunchTemplate
  89. Version: !GetAtt InstanceLaunchTemplate.LatestVersionNumber
  90. Tags:
  91. - Key: Name
  92. Value: !Sub '${AWS::StackName}_2'
  93. Outputs:
  94. PublicIp:
  95. Description: The DNS name for the created instance
  96. Value: !Sub "${Instance.PublicIp}"
  97. Export:
  98. Name: !Sub "${AWS::StackName}PublicIp"
  99. PublicIp2:
  100. Description: The DNS name for the created instance
  101. Value: !Sub "${Instance2.PublicIp}"
  102. Export:
  103. Name: !Sub "${AWS::StackName}PublicIp2"