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.

546 lines
16 KiB

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