Guest User

Untitled

a guest
Jul 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.93 KB | None | 0 0
  1. AWSTemplateFormatVersion: '2010-09-09'
  2. Description: Creates a VPC that and then creates a peering connection with an existing
  3. VPC that you specify.
  4. Parameters:
  5. EC2KeyPairName:
  6. Description: Name of an existing EC2 KeyPair to enable SSH access to the instances
  7. Type: AWS::EC2::KeyPair::KeyName
  8. ConstraintDescription: must be the name of an existing EC2 KeyPair.
  9. InstanceType:
  10. Description: EC2 instance type
  11. Type: String
  12. Default: t1.micro
  13. AllowedValues:
  14. - t1.micro
  15. - m1.small
  16. - m3.medium
  17. - m3.large
  18. - m3.xlarge
  19. - m3.2xlarge
  20. - c3.large
  21. - c3.xlarge
  22. - c3.2xlarge
  23. - c3.4xlarge
  24. - c3.8xlarge
  25. ConstraintDescription: must be a valid EC2 instance type.
  26. myVPCIDCIDRRange:
  27. Description: The IP address range for your new VPC.
  28. Type: String
  29. MinLength: '9'
  30. MaxLength: '18'
  31. Default: 10.1.0.0/16
  32. AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
  33. ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
  34. myPrivateVPCIDCIDRRange:
  35. Description: The IP address range for your new Private VPC.
  36. Type: String
  37. MinLength: '9'
  38. MaxLength: '18'
  39. Default: 10.0.0.0/16
  40. AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
  41. ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
  42. EC2SubnetCIDRRange:
  43. Description: The IP address range for a subnet in myPrivateVPC.
  44. Type: String
  45. MinLength: '9'
  46. MaxLength: '18'
  47. Default: 10.0.0.0/24
  48. AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
  49. ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
  50. EC2PublicSubnetCIDRRange:
  51. Description: The IP address range for a subnet in myVPC.
  52. Type: String
  53. MinLength: '9'
  54. MaxLength: '18'
  55. Default: 10.1.0.0/24
  56. AllowedPattern: "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
  57. ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
  58. Mappings:
  59. AWSRegionToAMI:
  60. us-east-1:
  61. '64': ami-fb8e9292
  62. us-west-2:
  63. '64': ami-043a5034
  64. us-west-1:
  65. '64': ami-7aba833f
  66. eu-west-1:
  67. '64': ami-2918e35e
  68. ap-southeast-1:
  69. '64': ami-b40d5ee6
  70. ap-southeast-2:
  71. '64': ami-3b4bd301
  72. ap-northeast-1:
  73. '64': ami-c9562fc8
  74. sa-east-1:
  75. '64': ami-215dff3c
  76. Resources:
  77. myPrivateVPC:
  78. Type: AWS::EC2::VPC
  79. Properties:
  80. CidrBlock:
  81. Ref: myPrivateVPCIDCIDRRange
  82. EnableDnsSupport: false
  83. EnableDnsHostnames: false
  84. InstanceTenancy: default
  85. myPrivateEC2Subnet:
  86. Type: AWS::EC2::Subnet
  87. Properties:
  88. VpcId:
  89. Ref: myPrivateVPC
  90. CidrBlock:
  91. Ref: EC2SubnetCIDRRange
  92. RouteTable:
  93. Type: AWS::EC2::RouteTable
  94. Properties:
  95. VpcId:
  96. Ref: myPrivateVPC
  97. PeeringRoute1:
  98. Type: AWS::EC2::Route
  99. Properties:
  100. DestinationCidrBlock: 0.0.0.0/0
  101. RouteTableId:
  102. Ref: RouteTable
  103. VpcPeeringConnectionId:
  104. Ref: myVPCPeeringConnection
  105. SubnetRouteTableAssociation:
  106. Type: AWS::EC2::SubnetRouteTableAssociation
  107. Properties:
  108. SubnetId:
  109. Ref: myPrivateEC2Subnet
  110. RouteTableId:
  111. Ref: RouteTable
  112. myVPC:
  113. Type: AWS::EC2::VPC
  114. Properties:
  115. CidrBlock:
  116. Ref: myVPCIDCIDRRange
  117. EnableDnsSupport: true
  118. EnableDnsHostnames: true
  119. InstanceTenancy: default
  120. PublicSubnet:
  121. Type: AWS::EC2::Subnet
  122. Properties:
  123. CidrBlock:
  124. Ref: EC2PublicSubnetCIDRRange
  125. VpcId:
  126. Ref: myVPC
  127. myInternetGateway:
  128. Type: AWS::EC2::InternetGateway
  129. AttachGateway:
  130. Type: AWS::EC2::VPCGatewayAttachment
  131. Properties:
  132. VpcId:
  133. Ref: myVPC
  134. InternetGatewayId:
  135. Ref: myInternetGateway
  136. PublicRouteTable:
  137. Type: AWS::EC2::RouteTable
  138. Properties:
  139. VpcId:
  140. Ref: myVPC
  141. PeeringRoute2:
  142. Type: AWS::EC2::Route
  143. Properties:
  144. DestinationCidrBlock:
  145. Ref: myPrivateVPCIDCIDRRange
  146. RouteTableId:
  147. Ref: PublicRouteTable
  148. VpcPeeringConnectionId:
  149. Ref: myVPCPeeringConnection
  150. PublicRoute:
  151. Type: AWS::EC2::Route
  152. DependsOn: AttachGateway
  153. Properties:
  154. RouteTableId:
  155. Ref: PublicRouteTable
  156. DestinationCidrBlock: 0.0.0.0/0
  157. GatewayId:
  158. Ref: myInternetGateway
  159. PublicSubnetRouteTableAssociation:
  160. Type: AWS::EC2::SubnetRouteTableAssociation
  161. Properties:
  162. SubnetId:
  163. Ref: PublicSubnet
  164. RouteTableId:
  165. Ref: PublicRouteTable
  166. myPrivateVPCEC2SecurityGroup:
  167. Type: AWS::EC2::SecurityGroup
  168. Properties:
  169. GroupDescription: Private instance security group
  170. VpcId:
  171. Ref: myPrivateVPC
  172. SecurityGroupIngress:
  173. - IpProtocol: "-1"
  174. FromPort: '0'
  175. ToPort: '65535'
  176. CidrIp: 0.0.0.0/0
  177. myVPCEC2SecurityGroup:
  178. Type: AWS::EC2::SecurityGroup
  179. Properties:
  180. GroupDescription: Public instance security group
  181. VpcId:
  182. Ref: myVPC
  183. SecurityGroupIngress:
  184. - IpProtocol: tcp
  185. FromPort: '80'
  186. ToPort: '80'
  187. CidrIp: 0.0.0.0/0
  188. - IpProtocol: tcp
  189. FromPort: '22'
  190. ToPort: '22'
  191. CidrIp: 0.0.0.0/0
  192. myPrivateInstance:
  193. Type: AWS::EC2::Instance
  194. Properties:
  195. SecurityGroupIds:
  196. - Ref: myPrivateVPCEC2SecurityGroup
  197. SubnetId:
  198. Ref: myPrivateEC2Subnet
  199. KeyName:
  200. Ref: EC2KeyPairName
  201. ImageId:
  202. Fn::FindInMap:
  203. - AWSRegionToAMI
  204. - Ref: AWS::Region
  205. - '64'
  206. myInstance:
  207. Type: AWS::EC2::Instance
  208. Properties:
  209. NetworkInterfaces:
  210. - AssociatePublicIpAddress: 'true'
  211. DeviceIndex: '0'
  212. GroupSet:
  213. - Ref: myVPCEC2SecurityGroup
  214. SubnetId:
  215. Ref: PublicSubnet
  216. KeyName:
  217. Ref: EC2KeyPairName
  218. ImageId:
  219. Fn::FindInMap:
  220. - AWSRegionToAMI
  221. - Ref: AWS::Region
  222. - '64'
  223. myVPCPeeringConnection:
  224. Type: AWS::EC2::VPCPeeringConnection
  225. Properties:
  226. VpcId:
Add Comment
Please, Sign In to add comment