vpc+role+elb.yaml 16 KB

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