You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

545 lines
16 KiB

  1. {
  2. "AWSTemplateFormatVersion": "2010-09-09",
  3. "Parameters": {
  4. "paramImageID": {
  5. "Type": "AWS::EC2::Image::Id",
  6. "Default": "ami-f573e19a",
  7. "Description": "Amazon Image ID (Amazon Linux), Frankfurt ami-f573e19a, N. Virginia ami-4dd18837"
  8. },
  9. "paramInstanceType": {
  10. "Type": "String",
  11. "Default": "t2.nano",
  12. "AllowedValues": [
  13. "t2.nano",
  14. "t2.micro",
  15. "m1.small"
  16. ],
  17. "Description": "Enter t2.micro, m1.small, or m1.large. Default is t2.micro."
  18. },
  19. "paramKeyPair": {
  20. "Type": "AWS::EC2::KeyPair::KeyName",
  21. "Description": "Amazon EC2 Key Pair"
  22. },
  23. "paramIamInstanceRole": {
  24. "Type": "String",
  25. "Default": "ec2-s3-vertsys-access-role",
  26. "Description": "IAM Instance Role"
  27. }
  28. },
  29. "Resources": {
  30. "lcVertSysAutoScaleConfigv11": {
  31. "Type": "AWS::AutoScaling::LaunchConfiguration",
  32. "Properties": {
  33. "AssociatePublicIpAddress": true,
  34. "ImageId": {
  35. "Ref": "paramImageID"
  36. },
  37. "InstanceType": {
  38. "Ref": "paramInstanceType"
  39. },
  40. "KeyName": {
  41. "Ref": "paramKeyPair"
  42. },
  43. "IamInstanceProfile": {
  44. "Ref": "paramIamInstanceRole"
  45. },
  46. "SecurityGroups": [
  47. {
  48. "Ref": "sgCloudCompDemoSecurityGroup"
  49. }
  50. ],
  51. "UserData": {
  52. "Fn::Base64": {
  53. "Fn::Join": [
  54. "",
  55. [
  56. "#!/bin/bash\n",
  57. "\n",
  58. "# this script will be run during the boot process by each VertSys instance created\n",
  59. "# in AWS currently this is a plain bash script that requires a RedHat based image\n",
  60. "# (AMI) could be ported to cloud-init for better compatibility with other Linux\n",
  61. "# distros\n",
  62. "#\n",
  63. "# see https://docs.aws.amazon.com/de_de/AWSEC2/latest/UserGuide/user-data.html\n",
  64. "\n",
  65. "# Config\n",
  66. "SCRIPT_ROOT_PATH=\"/tmp/init-script\"\n",
  67. "VERTSYS_PATH=\"$SCRIPT_ROOT_PATH/verteilte-systeme-bsc-ai-examples/VerteilteSysteme-Examples/build/\"\n",
  68. "#JARS = \"TCPServer.jar TCPServerMulti.jar UDPServer.jar UDPServerMulti.jar UDPTimeCounterServer.jar TCPTimeCounterServer.jar TCPPerfServer.jar\"\n",
  69. "JARS=\"TCPServer.jar TCPPerfServer.jar UDPServer.jar UDPTimeCounterServer.jar TCPTimeCounterServer.jar TCPTimeCounterRESTServer.jar\"\n",
  70. "REPO=\"https://gogs.informatik.hs-fulda.de/srieger/verteilte-systeme-bsc-ai-examples.git\"\n",
  71. "\n",
  72. "# Create path to run the script\n",
  73. "mkdir $SCRIPT_ROOT_PATH\n",
  74. "cd $SCRIPT_ROOT_PATH\n",
  75. "\n",
  76. "# fetch user-data (should be the content of this script itself ;)) to be able check it later and run it again\n",
  77. "wget http://169.254.169.254/latest/user-data\n",
  78. "chmod +x user-data\n",
  79. "wget http://169.254.169.254/latest/meta-data/placement/availability-zone\n",
  80. "\n",
  81. "# setting console prompt to include location (availability zone and region in AWS)\n",
  82. "echo \"PS1='[\\u@\\h@\\e[32m`cat /tmp/init-script/availability-zone`\\e[32m \\W]$ '\" >>/root/.bashrc\n",
  83. "echo \"PS1='[\\u@\\h@\\e[32m`cat /tmp/init-script/availability-zone`\\e[39m \\W]$ '\" >>/home/ec2-user/.bashrc\n",
  84. "\n",
  85. "# wait for internet connection, should not be necessary, but just in case ;)\n",
  86. "while ! ping -c 1 -W 1 8.8.8.8; do\n",
  87. " echo \"Waiting for 8.8.8.8 - network interface might be down...\"\n",
  88. " sleep 1\n",
  89. "done\n",
  90. "\n",
  91. "# installation of required packages\n",
  92. "echo \"Installing packages...\"\n",
  93. "sudo yum update -y\n",
  94. "sudo yum install -y java git\n",
  95. "#rm -rf verteilte-systeme-bsc-ai-examples\n",
  96. "if [ ! -d $VERTSYS_PATH ]; then\n",
  97. " echo \"Cloning repo...\"\n",
  98. " git clone $REPO\n",
  99. "fi\n",
  100. "\n",
  101. "# killall running screens, .e.g to cleanup if script is run again after boot\n",
  102. "killall screen\n",
  103. "# start all jars\n",
  104. "echo \"Starting JARS: ${JARS}...\"\n",
  105. "for JAR in $JARS; do\n",
  106. " echo \"Starting ${JAR}...\"\n",
  107. " sudo screen -dmS $JAR -L java -jar $VERTSYS_PATH/$JAR\n",
  108. "done\n",
  109. "\n",
  110. "# wait a second, to allow java services to start\n",
  111. "sleep 1\n",
  112. "\n",
  113. "# output status of ports 36000-36199 and all running processes\n",
  114. "echo \"Status:\"\n",
  115. "sudo netstat -taupen | grep 36[0,1][0-9][0-9]\n",
  116. "sudo ps aux | grep java\n",
  117. "\n",
  118. "# Example for path and contents:\n",
  119. "#\n",
  120. "# ./verteilte-systeme-bsc-ai-examples/VerteilteSysteme-Examples/build/\n",
  121. "#\n",
  122. "#build-server-jars.xml TCPServerMulti.jar\n",
  123. "#RMIEchoServer.jar UDPServer.jar\n",
  124. "#RMIMandelbrotCalculationsServer.jar UDPServerMulti.jar\n",
  125. "#TCPPerfServer.jar UDPTimeCounterServer.jar\n",
  126. "#TCPServer.jar\n"
  127. ]
  128. ]
  129. }
  130. }
  131. }
  132. },
  133. "vpcCloudCompCounterDemo": {
  134. "Type": "AWS::EC2::VPC",
  135. "Properties": {
  136. "CidrBlock": "10.0.0.0/16",
  137. "EnableDnsSupport": "true",
  138. "EnableDnsHostnames": "true",
  139. "Tags": [
  140. {
  141. "Key": "Name",
  142. "Value": "vpcCloudCompCounterDemo"
  143. }
  144. ]
  145. }
  146. },
  147. "subnetCloudCompCounterDemoPublicSubnetAz1": {
  148. "Type": "AWS::EC2::Subnet",
  149. "Properties": {
  150. "VpcId": {
  151. "Ref": "vpcCloudCompCounterDemo"
  152. },
  153. "CidrBlock": "10.0.0.0/24",
  154. "AvailabilityZone": {
  155. "Fn::Select": [
  156. "0",
  157. {
  158. "Fn::GetAZs": {
  159. "Ref": "AWS::Region"
  160. }
  161. }
  162. ]
  163. },
  164. "Tags": [
  165. {
  166. "Key": "Name",
  167. "Value": "subnetCloudCompCounterDemoPublicSubnetAz1"
  168. }
  169. ]
  170. }
  171. },
  172. "subnetCloudCompCounterDemoPublicSubnetAz2": {
  173. "Type": "AWS::EC2::Subnet",
  174. "Properties": {
  175. "VpcId": {
  176. "Ref": "vpcCloudCompCounterDemo"
  177. },
  178. "CidrBlock": "10.0.1.0/24",
  179. "AvailabilityZone": {
  180. "Fn::Select": [
  181. "1",
  182. {
  183. "Fn::GetAZs": {
  184. "Ref": "AWS::Region"
  185. }
  186. }
  187. ]
  188. },
  189. "Tags": [
  190. {
  191. "Key": "Name",
  192. "Value": "subnetCloudCompCounterDemoPublicSubnetAz2"
  193. }
  194. ]
  195. }
  196. },
  197. "igCloudCompCounterDemo": {
  198. "Type": "AWS::EC2::InternetGateway",
  199. "Properties": {
  200. "Tags": [
  201. {
  202. "Key": "Name",
  203. "Value": "igCloudCompCounterDemo"
  204. }
  205. ]
  206. }
  207. },
  208. "attachGateway": {
  209. "Type": "AWS::EC2::VPCGatewayAttachment",
  210. "Properties": {
  211. "VpcId": {
  212. "Ref": "vpcCloudCompCounterDemo"
  213. },
  214. "InternetGatewayId": {
  215. "Ref": "igCloudCompCounterDemo"
  216. }
  217. }
  218. },
  219. "routetableViaIgw": {
  220. "Type": "AWS::EC2::RouteTable",
  221. "Properties": {
  222. "VpcId": {
  223. "Ref": "vpcCloudCompCounterDemo"
  224. },
  225. "Tags": [
  226. {
  227. "Key": "Name",
  228. "Value": "routetableViaIgw"
  229. }
  230. ]
  231. }
  232. },
  233. "publicrouteViaIgw": {
  234. "Type": "AWS::EC2::Route",
  235. "DependsOn": "attachGateway",
  236. "Properties": {
  237. "RouteTableId": {
  238. "Ref": "routetableViaIgw"
  239. },
  240. "DestinationCidrBlock": "0.0.0.0/0",
  241. "GatewayId": {
  242. "Ref": "igCloudCompCounterDemo"
  243. }
  244. }
  245. },
  246. "publicsubnet1RouteTableAssociation": {
  247. "Type": "AWS::EC2::SubnetRouteTableAssociation",
  248. "Properties": {
  249. "SubnetId": {
  250. "Ref": "subnetCloudCompCounterDemoPublicSubnetAz1"
  251. },
  252. "RouteTableId": {
  253. "Ref": "routetableViaIgw"
  254. }
  255. }
  256. },
  257. "publicsubnet2RouteTableAssociation": {
  258. "Type": "AWS::EC2::SubnetRouteTableAssociation",
  259. "Properties": {
  260. "SubnetId": {
  261. "Ref": "subnetCloudCompCounterDemoPublicSubnetAz2"
  262. },
  263. "RouteTableId": {
  264. "Ref": "routetableViaIgw"
  265. }
  266. }
  267. },
  268. "sgCloudCompDemoSecurityGroup": {
  269. "Type": "AWS::EC2::SecurityGroup",
  270. "Properties": {
  271. "GroupDescription": "CloudComp Counter Demo",
  272. "VpcId": {
  273. "Ref": "vpcCloudCompCounterDemo"
  274. }
  275. }
  276. },
  277. "ingress1": {
  278. "Type": "AWS::EC2::SecurityGroupIngress",
  279. "Properties": {
  280. "GroupId": {
  281. "Ref": "sgCloudCompDemoSecurityGroup"
  282. },
  283. "IpProtocol": "tcp",
  284. "FromPort": "36037",
  285. "ToPort": "36137",
  286. "CidrIp": "0.0.0.0/0"
  287. }
  288. },
  289. "ingress2": {
  290. "Type": "AWS::EC2::SecurityGroupIngress",
  291. "Properties": {
  292. "GroupId": {
  293. "Ref": "sgCloudCompDemoSecurityGroup"
  294. },
  295. "IpProtocol": "tcp",
  296. "FromPort": "22",
  297. "ToPort": "22",
  298. "CidrIp": "0.0.0.0/0"
  299. }
  300. },
  301. "ingress3": {
  302. "Type": "AWS::EC2::SecurityGroupIngress",
  303. "Properties": {
  304. "GroupId": {
  305. "Ref": "sgCloudCompDemoSecurityGroup"
  306. },
  307. "IpProtocol": "udp",
  308. "FromPort": "36037",
  309. "ToPort": "36137",
  310. "CidrIp": "0.0.0.0/0"
  311. }
  312. },
  313. "egress1": {
  314. "Type": "AWS::EC2::SecurityGroupEgress",
  315. "Properties": {
  316. "GroupId": {
  317. "Ref": "sgCloudCompDemoSecurityGroup"
  318. },
  319. "IpProtocol": "-1",
  320. "CidrIp": "0.0.0.0/0"
  321. }
  322. },
  323. "asgCloudCompAutoScaleGroup": {
  324. "Type": "AWS::AutoScaling::AutoScalingGroup",
  325. "Properties": {
  326. "AvailabilityZones": [
  327. {
  328. "Fn::Select": [
  329. "0",
  330. {
  331. "Fn::GetAZs": {
  332. "Ref": "AWS::Region"
  333. }
  334. }
  335. ]
  336. },
  337. {
  338. "Fn::Select": [
  339. "1",
  340. {
  341. "Fn::GetAZs": {
  342. "Ref": "AWS::Region"
  343. }
  344. }
  345. ]
  346. }
  347. ],
  348. "TargetGroupARNs": [
  349. {
  350. "Ref": "elbCloudCompTargetGroup"
  351. }
  352. ],
  353. "Cooldown": "30",
  354. "DesiredCapacity": "1",
  355. "HealthCheckGracePeriod": "60",
  356. "HealthCheckType": "EC2",
  357. "MaxSize": "3",
  358. "MinSize": "1",
  359. "VPCZoneIdentifier": [
  360. {
  361. "Ref": "subnetCloudCompCounterDemoPublicSubnetAz1"
  362. },
  363. {
  364. "Ref": "subnetCloudCompCounterDemoPublicSubnetAz2"
  365. }
  366. ],
  367. "LaunchConfigurationName": {
  368. "Ref": "lcVertSysAutoScaleConfigv11"
  369. },
  370. "MetricsCollection": [
  371. {
  372. "Granularity": "1Minute",
  373. "Metrics": [
  374. "GroupPendingInstances",
  375. "GroupMinSize",
  376. "GroupDesiredCapacity",
  377. "GroupTerminatingInstances",
  378. "GroupInServiceInstances",
  379. "GroupStandbyInstances",
  380. "GroupMaxSize",
  381. "GroupTotalInstances"
  382. ]
  383. }
  384. ],
  385. "TerminationPolicies": [
  386. "Default"
  387. ]
  388. }
  389. },
  390. "sgCloudCompScalePolicy": {
  391. "Type": "AWS::AutoScaling::ScalingPolicy",
  392. "DependsOn": "elbCloudCompListener",
  393. "Properties": {
  394. "PolicyType": "TargetTrackingScaling",
  395. "EstimatedInstanceWarmup": 60,
  396. "TargetTrackingConfiguration": {
  397. "DisableScaleIn": false,
  398. "TargetValue": 5,
  399. "PredefinedMetricSpecification": {
  400. "PredefinedMetricType": "ALBRequestCountPerTarget",
  401. "ResourceLabel": {
  402. "Fn::Join": [
  403. "/",
  404. [
  405. "app/elbCloudCompLoadBalancer",
  406. {
  407. "Fn::Select": [
  408. "3",
  409. {
  410. "Fn::Split": [
  411. "/",
  412. {
  413. "Ref": "elbCloudCompLoadBalancer"
  414. }
  415. ]
  416. }
  417. ]
  418. },
  419. "targetgroup/elbCloudCompTargetGroup",
  420. {
  421. "Fn::Select": [
  422. "2",
  423. {
  424. "Fn::Split": [
  425. "/",
  426. {
  427. "Ref": "elbCloudCompTargetGroup"
  428. }
  429. ]
  430. }
  431. ]
  432. }
  433. ]
  434. ]
  435. }
  436. }
  437. },
  438. "AutoScalingGroupName": {
  439. "Ref": "asgCloudCompAutoScaleGroup"
  440. }
  441. }
  442. },
  443. "elbCloudCompLoadBalancer": {
  444. "Type": "AWS::ElasticLoadBalancingV2::LoadBalancer",
  445. "Properties": {
  446. "Name": "elbCloudCompLoadBalancer",
  447. "IpAddressType": "ipv4",
  448. "Type": "application",
  449. "Scheme": "internet-facing",
  450. "SecurityGroups": [
  451. {
  452. "Ref": "sgCloudCompDemoSecurityGroup"
  453. }
  454. ],
  455. "Subnets": [
  456. {
  457. "Ref": "subnetCloudCompCounterDemoPublicSubnetAz1"
  458. },
  459. {
  460. "Ref": "subnetCloudCompCounterDemoPublicSubnetAz2"
  461. }
  462. ]
  463. }
  464. },
  465. "elbCloudCompTargetGroup": {
  466. "Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
  467. "Properties": {
  468. "Port": 36042,
  469. "HealthCheckIntervalSeconds": 30,
  470. "HealthCheckTimeoutSeconds": 5,
  471. "HealthyThresholdCount": 2,
  472. "UnhealthyThresholdCount": 2,
  473. "HealthCheckPath": "/counter",
  474. "HealthCheckProtocol": "HTTP",
  475. "TargetGroupAttributes": [
  476. {
  477. "Key": "deregistration_delay.timeout_seconds",
  478. "Value": "20"
  479. }
  480. ],
  481. "Protocol": "HTTP",
  482. "TargetType": "instance",
  483. "Matcher": {
  484. "HttpCode": "200"
  485. },
  486. "Name": "elbCloudCompTargetGroup",
  487. "VpcId": {
  488. "Ref": "vpcCloudCompCounterDemo"
  489. }
  490. }
  491. },
  492. "elbCloudCompListener": {
  493. "Type": "AWS::ElasticLoadBalancingV2::Listener",
  494. "Properties": {
  495. "LoadBalancerArn": {
  496. "Ref": "elbCloudCompLoadBalancer"
  497. },
  498. "Protocol": "HTTP",
  499. "Port": 36042,
  500. "DefaultActions": [
  501. {
  502. "Type": "forward",
  503. "TargetGroupArn": {
  504. "Ref": "elbCloudCompTargetGroup"
  505. }
  506. }
  507. ]
  508. }
  509. }
  510. },
  511. "Outputs": {
  512. "LoadBalancer": {
  513. "Description": "Load Balancer",
  514. "Value": {
  515. "Ref": "elbCloudCompLoadBalancer"
  516. }
  517. },
  518. "LoadBalancerDns": {
  519. "Description": "Load Balancer DNS",
  520. "Value": {
  521. "Fn::GetAtt": [
  522. "elbCloudCompLoadBalancer",
  523. "DNSName"
  524. ]
  525. }
  526. },
  527. "LoadBalancerURL": {
  528. "Description": "Load Balancer URL",
  529. "Value": {
  530. "Fn::Join": [
  531. ":",
  532. [
  533. {
  534. "Fn::GetAtt": [
  535. "elbCloudCompLoadBalancer",
  536. "DNSName"
  537. ]
  538. },
  539. "36042/counter"
  540. ]
  541. ]
  542. }
  543. }
  544. },
  545. "Description": "CloudComp Counter Demo"
  546. }