updata-vpc.yaml 16 KB

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