vpc+role+elb.yaml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. AWSTemplateFormatVersion: 2010-09-09
  2. Resources:
  3. ApplicationLoadBalancer:
  4. Type: 'AWS::ElasticLoadBalancingV2::LoadBalancer'
  5. Properties:
  6. Subnets:
  7. - !Ref pubnet1
  8. - !Ref pubnet2
  9. SecurityGroups:
  10. - !Ref elbgroup
  11. Metadata:
  12. 'AWS::CloudFormation::Designer':
  13. id: 01cf8a1b-c08c-4410-b833-5bab98a4cc0d
  14. ALBListener:
  15. Type: 'AWS::ElasticLoadBalancingV2::Listener'
  16. Properties:
  17. DefaultActions:
  18. - Type: forward
  19. TargetGroupArn: !Ref ALBTargetGroup
  20. LoadBalancerArn: !Ref ApplicationLoadBalancer
  21. Port: '81'
  22. Protocol: HTTP
  23. Metadata:
  24. 'AWS::CloudFormation::Designer':
  25. id: cf883cbd-fd01-45a1-b42e-3cc732475a48
  26. ALBListenerRule:
  27. Type: 'AWS::ElasticLoadBalancingV2::ListenerRule'
  28. Properties:
  29. Actions:
  30. - Type: forward
  31. TargetGroupArn: !Ref ALBTargetGroup
  32. Conditions:
  33. - Field: path-pattern
  34. Values:
  35. - /
  36. ListenerArn: !Ref ALBListener
  37. Priority: 1
  38. Metadata:
  39. 'AWS::CloudFormation::Designer':
  40. id: bfa5c894-73f0-40e1-a0ad-7a6d83d61f84
  41. ALBTargetGroup:
  42. Type: 'AWS::ElasticLoadBalancingV2::TargetGroup'
  43. Properties:
  44. HealthCheckIntervalSeconds: 30
  45. HealthCheckPath: /
  46. HealthCheckProtocol: HTTP
  47. HealthCheckTimeoutSeconds: 5
  48. HealthyThresholdCount: 3
  49. Port: 7777
  50. Protocol: HTTP
  51. UnhealthyThresholdCount: 5
  52. VpcId: !Ref vpc1
  53. Metadata:
  54. 'AWS::CloudFormation::Designer':
  55. id: da90ade6-53eb-497d-a36a-b4ab683f9948
  56. RootRole:
  57. Type: 'AWS::IAM::Role'
  58. Properties:
  59. AssumeRolePolicyDocument:
  60. Version: 2012-10-17
  61. Statement:
  62. - Effect: Allow
  63. Principal:
  64. Service:
  65. - lambda.amazonaws.com
  66. - ec2.amazonaws.com.cn
  67. - ecs-tasks.amazonaws.com
  68. - vpc-flow-logs.amazonaws.com
  69. Action:
  70. - 'sts:AssumeRole'
  71. Path: /
  72. RoleName: !Ref roleName
  73. Metadata:
  74. 'AWS::CloudFormation::Designer':
  75. id: 5a809822-8fad-40ca-bd0f-7aae64ae7b4a
  76. RolePolicies:
  77. Type: 'AWS::IAM::Policy'
  78. Properties:
  79. PolicyName: root
  80. PolicyDocument:
  81. Version: 2012-10-17
  82. Statement:
  83. - Effect: Allow
  84. Action: '*'
  85. Resource: '*'
  86. Roles:
  87. - Ref: RootRole
  88. Metadata:
  89. 'AWS::CloudFormation::Designer':
  90. id: 41ab1589-d187-45a1-99aa-379280c9f643
  91. RootInstanceProfile:
  92. Type: 'AWS::IAM::InstanceProfile'
  93. Properties:
  94. Path: /
  95. Roles:
  96. - Ref: RootRole
  97. Metadata:
  98. 'AWS::CloudFormation::Designer':
  99. id: 15050a6e-6cfb-43ec-b19f-c3c3102187d3
  100. vpc1:
  101. Type: 'AWS::EC2::VPC'
  102. Properties:
  103. CidrBlock: !Ref vpccidr
  104. EnableDnsHostnames: 'true'
  105. EnableDnsSupport: 'true'
  106. Tags:
  107. - Key: Name
  108. Value: vpc1
  109. Metadata:
  110. 'AWS::CloudFormation::Designer':
  111. id: 36050a81-2f2b-4482-9d6a-763dbad1b527
  112. pubnet1:
  113. Type: 'AWS::EC2::Subnet'
  114. Properties:
  115. AvailabilityZone: !Select
  116. - '0'
  117. - !GetAZs ''
  118. CidrBlock: !Ref pubnet1cidr
  119. Tags:
  120. - Key: Name
  121. Value: pubnet1
  122. VpcId: !Ref vpc1
  123. Metadata:
  124. 'AWS::CloudFormation::Designer':
  125. id: d00fad60-d71a-4bfc-988a-65236dea5a6f
  126. pubnet2:
  127. Type: 'AWS::EC2::Subnet'
  128. Properties:
  129. AvailabilityZone: !Select
  130. - '1'
  131. - !GetAZs ''
  132. CidrBlock: !Ref pubnet2cidr
  133. Tags:
  134. - Key: Name
  135. Value: pubnet2
  136. VpcId: !Ref vpc1
  137. Metadata:
  138. 'AWS::CloudFormation::Designer':
  139. id: dbc87cce-6f33-46fb-8684-24fc5008ad91
  140. webnet1:
  141. Type: 'AWS::EC2::Subnet'
  142. Properties:
  143. AvailabilityZone: !Select
  144. - '0'
  145. - !GetAZs ''
  146. CidrBlock: !Ref webnet1cidr
  147. Tags:
  148. - Key: Name
  149. Value: webnet1
  150. VpcId: !Ref vpc1
  151. Metadata:
  152. 'AWS::CloudFormation::Designer':
  153. id: 30f1713d-c319-4dcb-8730-c4baf0cb207a
  154. webnet2:
  155. Type: 'AWS::EC2::Subnet'
  156. Properties:
  157. AvailabilityZone: !Select
  158. - '1'
  159. - !GetAZs ''
  160. CidrBlock: !Ref webnet2cidr
  161. Tags:
  162. - Key: Name
  163. Value: webnet2
  164. VpcId: !Ref vpc1
  165. Metadata:
  166. 'AWS::CloudFormation::Designer':
  167. id: bd5423c4-721b-4194-a7ba-b8d4b437683a
  168. dbnet1:
  169. Type: 'AWS::EC2::Subnet'
  170. Properties:
  171. AvailabilityZone: !Select
  172. - '0'
  173. - !GetAZs ''
  174. CidrBlock: !Ref dbnet1cidr
  175. Tags:
  176. - Key: Name
  177. Value: dbnet1
  178. VpcId: !Ref vpc1
  179. Metadata:
  180. 'AWS::CloudFormation::Designer':
  181. id: d721de76-5cf2-416c-985d-2bd9d10d4c3c
  182. dbnet2:
  183. Type: 'AWS::EC2::Subnet'
  184. Properties:
  185. AvailabilityZone: !Select
  186. - '1'
  187. - !GetAZs ''
  188. CidrBlock: !Ref dbnet2cidr
  189. Tags:
  190. - Key: Name
  191. Value: dbnet2
  192. VpcId: !Ref vpc1
  193. Metadata:
  194. 'AWS::CloudFormation::Designer':
  195. id: d3655dff-3e6c-4e71-b429-782c249ead24
  196. table1:
  197. Type: 'AWS::EC2::RouteTable'
  198. Properties:
  199. Tags:
  200. - Key: Name
  201. Value: table1
  202. VpcId: !Ref vpc1
  203. Metadata:
  204. 'AWS::CloudFormation::Designer':
  205. id: 5a28c477-28f7-4f63-96e4-eba4f2af91c8
  206. table2:
  207. Type: 'AWS::EC2::RouteTable'
  208. Properties:
  209. Tags:
  210. - Key: Name
  211. Value: table2
  212. VpcId: !Ref vpc1
  213. Metadata:
  214. 'AWS::CloudFormation::Designer':
  215. id: e7cb3a54-60cc-4806-b6c5-51dd541555b2
  216. table3:
  217. Type: 'AWS::EC2::RouteTable'
  218. Properties:
  219. Tags:
  220. - Key: Name
  221. Value: table3
  222. VpcId: !Ref vpc1
  223. Metadata:
  224. 'AWS::CloudFormation::Designer':
  225. id: b031b8a3-c571-4e9b-967f-e777ca927d08
  226. igw1:
  227. Type: 'AWS::EC2::InternetGateway'
  228. Properties: {}
  229. Metadata:
  230. 'AWS::CloudFormation::Designer':
  231. id: 4f2d896c-333a-4e40-acf1-a4d29c7f1e04
  232. EC2VPCG2BPGG:
  233. Type: 'AWS::EC2::VPCGatewayAttachment'
  234. Properties:
  235. InternetGatewayId: !Ref igw1
  236. VpcId: !Ref vpc1
  237. Metadata:
  238. 'AWS::CloudFormation::Designer':
  239. id: 544c5488-107f-4d4f-99d7-f22003afd889
  240. natgateway1:
  241. Type: 'AWS::EC2::NatGateway'
  242. Properties:
  243. AllocationId: !GetAtt
  244. - eip1
  245. - AllocationId
  246. SubnetId: !Ref pubnet1
  247. Metadata:
  248. 'AWS::CloudFormation::Designer':
  249. id: df5bea53-45ac-47d0-ae9e-32e7d54a37a5
  250. natgateway2:
  251. Type: 'AWS::EC2::NatGateway'
  252. Properties:
  253. AllocationId: !GetAtt
  254. - eip2
  255. - AllocationId
  256. SubnetId: !Ref pubnet2
  257. Metadata:
  258. 'AWS::CloudFormation::Designer':
  259. id: b8570bf1-7fe5-4d58-8fb9-83e3660f2170
  260. eip1:
  261. Type: 'AWS::EC2::EIP'
  262. Properties: {}
  263. Metadata:
  264. 'AWS::CloudFormation::Designer':
  265. id: d77dbe47-fc90-4338-8ff2-af4000405dde
  266. eip2:
  267. Type: 'AWS::EC2::EIP'
  268. Properties: {}
  269. Metadata:
  270. 'AWS::CloudFormation::Designer':
  271. id: e8777cd9-8375-401a-ad6f-52051c09dc89
  272. EC2SRTA51E2B:
  273. Type: 'AWS::EC2::SubnetRouteTableAssociation'
  274. Properties:
  275. SubnetId: !Ref pubnet1
  276. RouteTableId: !Ref table1
  277. Metadata:
  278. 'AWS::CloudFormation::Designer':
  279. id: 72574f43-a5f8-4c3b-bcf7-f8b199887e9c
  280. EC2SRTA2YHOD:
  281. Type: 'AWS::EC2::SubnetRouteTableAssociation'
  282. Properties:
  283. SubnetId: !Ref pubnet2
  284. RouteTableId: !Ref table1
  285. Metadata:
  286. 'AWS::CloudFormation::Designer':
  287. id: f7e5fe7c-a1c1-48e0-8743-daa1f0e3fb06
  288. EC2SRTA2VWB8:
  289. Type: 'AWS::EC2::SubnetRouteTableAssociation'
  290. Properties:
  291. RouteTableId: !Ref table2
  292. SubnetId: !Ref webnet1
  293. Metadata:
  294. 'AWS::CloudFormation::Designer':
  295. id: 5b9f52cd-7dd4-4a0e-88d2-ebd48368e2a4
  296. EC2SRTA26CTN:
  297. Type: 'AWS::EC2::SubnetRouteTableAssociation'
  298. Properties:
  299. SubnetId: !Ref dbnet1
  300. RouteTableId: !Ref table2
  301. Metadata:
  302. 'AWS::CloudFormation::Designer':
  303. id: 3cedd898-d918-44c1-938d-cfc6512301ea
  304. EC2SRTAH6LA:
  305. Type: 'AWS::EC2::SubnetRouteTableAssociation'
  306. Properties:
  307. SubnetId: !Ref webnet2
  308. RouteTableId: !Ref table3
  309. Metadata:
  310. 'AWS::CloudFormation::Designer':
  311. id: 91524a30-078a-41c2-a34e-0f16b37b3691
  312. EC2SRTA1VSM:
  313. Type: 'AWS::EC2::SubnetRouteTableAssociation'
  314. Properties:
  315. SubnetId: !Ref dbnet2
  316. RouteTableId: !Ref table3
  317. Metadata:
  318. 'AWS::CloudFormation::Designer':
  319. id: 1220e1c3-e8c3-4f7a-998d-e60203564b8d
  320. route1:
  321. Type: 'AWS::EC2::Route'
  322. Properties:
  323. DestinationCidrBlock: 0.0.0.0/0
  324. GatewayId: !Ref igw1
  325. RouteTableId: !Ref table1
  326. Metadata:
  327. 'AWS::CloudFormation::Designer':
  328. id: d037ea69-ec83-4c36-92f7-12c199349fd9
  329. route2:
  330. Type: 'AWS::EC2::Route'
  331. Properties:
  332. DestinationCidrBlock: 0.0.0.0/0
  333. NatGatewayId: !Ref natgateway1
  334. RouteTableId: !Ref table2
  335. Metadata:
  336. 'AWS::CloudFormation::Designer':
  337. id: 64d213ca-d8f7-45f3-a53b-6001ad55ba0a
  338. route3:
  339. Type: 'AWS::EC2::Route'
  340. Properties:
  341. DestinationCidrBlock: 0.0.0.0/0
  342. NatGatewayId: !Ref natgateway2
  343. RouteTableId: !Ref table3
  344. Metadata:
  345. 'AWS::CloudFormation::Designer':
  346. id: c5cec4ea-e367-424f-9e78-92220722b760
  347. elbgroup:
  348. Type: 'AWS::EC2::SecurityGroup'
  349. Properties:
  350. GroupDescription: sg_elb
  351. GroupName: sg_elb
  352. Tags:
  353. - Key: Name
  354. Value: sg_elb
  355. SecurityGroupIngress:
  356. - IpProtocol: tcp
  357. FromPort: 80
  358. ToPort: 80
  359. CidrIp: 0.0.0.0/0
  360. SecurityGroupEgress:
  361. - CidrIp: 0.0.0.0/0
  362. IpProtocol: '-1'
  363. VpcId: !Ref vpc1
  364. Metadata:
  365. 'AWS::CloudFormation::Designer':
  366. id: 41ff46eb-edb8-456f-9183-4d7eea31e49a
  367. webgroup:
  368. Type: 'AWS::EC2::SecurityGroup'
  369. Properties:
  370. GroupDescription: !Ref sgName
  371. GroupName: !Ref sgName
  372. Tags:
  373. - Key: Name
  374. Value: !Ref sgName
  375. SecurityGroupIngress:
  376. - IpProtocol: tcp
  377. FromPort: 7777
  378. ToPort: 7777
  379. CidrIp: 0.0.0.0/0
  380. - IpProtocol: tcp
  381. FromPort: 22
  382. ToPort: 22
  383. CidrIp: 0.0.0.0/0
  384. SecurityGroupEgress:
  385. - CidrIp: 0.0.0.0/0
  386. IpProtocol: '-1'
  387. VpcId: !Ref vpc1
  388. Metadata:
  389. 'AWS::CloudFormation::Designer':
  390. id: 3d3c83e4-c428-4628-a0e2-d4415ec6cfd6
  391. dbgroup:
  392. Type: 'AWS::EC2::SecurityGroup'
  393. Properties:
  394. GroupDescription: dbgroup
  395. GroupName: elasticache_memcache
  396. Tags:
  397. - Key: Name
  398. Value: elasticache_memcache
  399. SecurityGroupIngress:
  400. - SourceSecurityGroupId: !Ref webgroup
  401. FromPort: !Ref cacheport
  402. ToPort: !Ref cacheport
  403. IpProtocol: tcp
  404. - SourceSecurityGroupId: !Ref webgroup
  405. FromPort: '2049'
  406. ToPort: '2049'
  407. IpProtocol: tcp
  408. - SourceSecurityGroupId: !Ref webgroup
  409. FromPort: '5432'
  410. ToPort: '5432'
  411. IpProtocol: tcp
  412. SecurityGroupEgress:
  413. - CidrIp: 0.0.0.0/0
  414. IpProtocol: '-1'
  415. VpcId: !Ref vpc1
  416. Metadata:
  417. 'AWS::CloudFormation::Designer':
  418. id: 6efe5731-b5ea-4e23-9b48-1353eaea32a1
  419. redissg:
  420. Type: 'AWS::EC2::SecurityGroup'
  421. Properties:
  422. GroupDescription: redissg
  423. GroupName: elasticache_redis
  424. Tags:
  425. - Key: Name
  426. Value: elasticache_redis
  427. SecurityGroupIngress:
  428. - SourceSecurityGroupId: !Ref webgroup
  429. FromPort: '6379'
  430. ToPort: '6379'
  431. IpProtocol: tcp
  432. - SourceSecurityGroupId: !Ref webgroup
  433. FromPort: '2049'
  434. ToPort: '2049'
  435. IpProtocol: tcp
  436. SecurityGroupEgress:
  437. - CidrIp: 0.0.0.0/0
  438. IpProtocol: '-1'
  439. VpcId: !Ref vpc1
  440. Metadata:
  441. 'AWS::CloudFormation::Designer':
  442. id: e2fe8abf-7e4a-472a-88e6-52c5b75b9924
  443. efssg:
  444. Type: 'AWS::EC2::SecurityGroup'
  445. Properties:
  446. GroupDescription: sgefs
  447. GroupName: sg_efs
  448. Tags:
  449. - Key: Name
  450. Value: sg_efs
  451. SecurityGroupIngress:
  452. - SourceSecurityGroupId: !Ref webgroup
  453. FromPort: '2049'
  454. ToPort: '2049'
  455. IpProtocol: tcp
  456. - SourceSecurityGroupId: !Ref lambdasg
  457. FromPort: '2049'
  458. ToPort: '2049'
  459. IpProtocol: tcp
  460. SecurityGroupEgress:
  461. - CidrIp: 0.0.0.0/0
  462. IpProtocol: '-1'
  463. VpcId: !Ref vpc1
  464. Metadata:
  465. 'AWS::CloudFormation::Designer':
  466. id: a2a71bad-d448-4630-ae7a-ac51d0366306
  467. cachegroup:
  468. Type: 'AWS::ElastiCache::SubnetGroup'
  469. Properties:
  470. CacheSubnetGroupName: cachegroup
  471. Description: cachegroup
  472. SubnetIds:
  473. - !Ref dbnet1
  474. - !Ref dbnet2
  475. Metadata:
  476. 'AWS::CloudFormation::Designer':
  477. id: 4c252f4a-8901-40df-b0a2-386cee29c258
  478. rdsgroup:
  479. Type: 'AWS::RDS::DBSubnetGroup'
  480. Properties:
  481. DBSubnetGroupDescription: rdsgroup
  482. DBSubnetGroupName: rdsgroup
  483. Tags:
  484. - Key: Name
  485. Value: rdsgroup
  486. SubnetIds:
  487. - !Ref dbnet1
  488. - !Ref dbnet2
  489. Metadata:
  490. 'AWS::CloudFormation::Designer':
  491. id: 00338a06-280d-4c12-9255-b77136a19138
  492. rdssg:
  493. Type: 'AWS::EC2::SecurityGroup'
  494. Properties:
  495. GroupDescription: sg_rds
  496. GroupName: sg_rds
  497. Tags:
  498. - Key: Name
  499. Value: sg_rds
  500. SecurityGroupIngress:
  501. - SourceSecurityGroupId: !Ref webgroup
  502. FromPort: '3306'
  503. ToPort: '3306'
  504. IpProtocol: tcp
  505. - SourceSecurityGroupId: !Ref webgroup
  506. FromPort: '5432'
  507. ToPort: '5432'
  508. IpProtocol: tcp
  509. - SourceSecurityGroupId: !Ref lambdasg
  510. FromPort: '5432'
  511. ToPort: '5432'
  512. IpProtocol: tcp
  513. - SourceSecurityGroupId: !Ref lambdasg
  514. FromPort: '3306'
  515. ToPort: '3306'
  516. IpProtocol: tcp
  517. SecurityGroupEgress:
  518. - CidrIp: 0.0.0.0/0
  519. IpProtocol: '-1'
  520. VpcId: !Ref vpc1
  521. Metadata:
  522. 'AWS::CloudFormation::Designer':
  523. id: 6efe5731-b5ea-4e23-9b48-1353eaea32a1
  524. lambdasg:
  525. Type: 'AWS::EC2::SecurityGroup'
  526. Properties:
  527. GroupDescription: sg_lambda
  528. GroupName: sg_lambda
  529. Tags:
  530. - Key: Name
  531. Value: sg_lambda
  532. SecurityGroupEgress:
  533. - CidrIp: 0.0.0.0/0
  534. IpProtocol: '-1'
  535. VpcId: !Ref vpc1
  536. Metadata:
  537. 'AWS::CloudFormation::Designer':
  538. id: 6efe5731-b5ea-4e23-9b48-1353eaea32a1
  539. Parameters:
  540. vpccidr:
  541. Type: String
  542. Default: 192.168.0.0/16
  543. pubnet1cidr:
  544. Type: String
  545. Default: 192.168.1.0/24
  546. pubnet2cidr:
  547. Type: String
  548. Default: 192.168.2.0/24
  549. webnet1cidr:
  550. Type: String
  551. Default: 192.168.3.0/24
  552. webnet2cidr:
  553. Type: String
  554. Default: 192.168.4.0/24
  555. dbnet1cidr:
  556. Type: String
  557. Default: 192.168.5.0/24
  558. dbnet2cidr:
  559. Type: String
  560. Default: 192.168.6.0/24
  561. cacheport:
  562. Type: String
  563. Default: '11211'
  564. sgName:
  565. Type: String
  566. Default: sg_ai
  567. roleName:
  568. Type: String
  569. Default: BaseRole
  570. Outputs:
  571. PUBnet1id:
  572. Value: !Ref pubnet1
  573. PUBnet2id:
  574. Value: !Ref pubnet2
  575. WEBbnet1id:
  576. Value: !Ref webnet1
  577. WEBnet2id:
  578. Value: !Ref webnet2
  579. DBnet1id:
  580. Value: !Ref dbnet1
  581. DBnet2id:
  582. Value: !Ref dbnet2
  583. Vpcid:
  584. Value: !Ref vpc1
  585. ELBsg:
  586. Value: !Ref elbgroup
  587. ServerSG:
  588. Value: !Ref webgroup
  589. MemSg:
  590. Value: !Ref dbgroup
  591. EFSsg:
  592. Value: !Ref efssg
  593. RedisSg:
  594. Value: !Ref redissg