From c5aaf2f4f7529e3c193ada7d4ac3046f70ba5e40 Mon Sep 17 00:00:00 2001
From: Sebastian Rieger <sebastian.rieger@informatik.hs-fulda.de>
Date: Mon, 30 May 2022 13:34:52 +0200
Subject: [PATCH] changed keyName to vockey, changed instanceType to t2.micro
 as t2.nano can run into out of memory situation when starting mariadb

---
 .../aws-boto3-rds-db/start.py                     | 10 ++++++----
 .../aws-boto3-standalone-db-autoscaling/start.py  | 14 ++++++++++----
 .../create-loadbalancer.py                        |  8 ++++++--
 .../start-and-add-new-target.py                   | 11 ++++++++---
 .../aws-boto3-standalone-db/start.py              | 15 ++++++++++++---
 5 files changed, 42 insertions(+), 16 deletions(-)

diff --git a/example-projects/tug-of-war-in-the-clouds/aws-boto3-rds-db/start.py b/example-projects/tug-of-war-in-the-clouds/aws-boto3-rds-db/start.py
index a342be6..c59c752 100644
--- a/example-projects/tug-of-war-in-the-clouds/aws-boto3-rds-db/start.py
+++ b/example-projects/tug-of-war-in-the-clouds/aws-boto3-rds-db/start.py
@@ -7,8 +7,8 @@ from botocore.exceptions import ClientError
 #
 ################################################################################################
 
-print("!!!!!!!! You cannot use RDS in AWS Educate Account !!!!!!!!")
-exit(-1)
+# print("!!!!!!!! You cannot use RDS in AWS Educate Account !!!!!!!!")
+# exit(-1)
 
 # place your credentials in ~/.aws/credentials, as mentioned in AWS Educate Classroom,
 # Account Details, AWC CLI -> Show (Copy and paste the following into ~/.aws/credentials)
@@ -21,6 +21,7 @@ availabilityZone = 'us-east-1a'
 
 # AMI ID of Amazon Linux 2 image 64-bit x86 in us-east-1 (can be retrieved, e.g., at
 # https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#LaunchInstanceWizard:)
+# TODO update to recent version of Amazon Linux 2 AMI?
 imageId = 'ami-0d5eff06f840b45e9'
 # for eu-central-1, AMI ID of Amazon Linux 2 would be:
 # imageId = 'ami-0cc293023f983ed53'
@@ -153,8 +154,9 @@ response = rdsClient.create_db_instance(DBInstanceIdentifier="tug-of-war-rds-db1
     MasterUsername='cloud_tug_of_war',
     MasterUserPassword='cloudpass',
     VpcSecurityGroupIds=[security_group_id],
-    #DBInstanceClass='db.m3.2xlarge',
-    DBInstanceClass='db.t3.micro',
+    # DBInstanceClass='db.m3.2xlarge',
+    # DBInstanceClass='db.t3.micro',
+    DBInstanceClass='db.t2.small',
     Tags=[
         {'Key': 'Name', 'Value': 'tug-of-war-rds-db1'},
         {'Key': 'tug-of-war-rds', 'Value': 'db'}
diff --git a/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db-autoscaling/start.py b/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db-autoscaling/start.py
index dbfa1e0..be9c2b4 100644
--- a/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db-autoscaling/start.py
+++ b/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db-autoscaling/start.py
@@ -10,8 +10,8 @@ from botocore.exceptions import ClientError
 #
 ################################################################################################
 
-print("!!!!!!!! You cannot use Auto Scaling Group in AWS Educate Account !!!!!!!!")
-exit(-1)
+# print("!!!!!!!! You cannot use Auto Scaling Group in AWS Educate Account !!!!!!!!")
+# exit(-1)
 
 # place your credentials in ~/.aws/credentials, as mentioned in AWS Educate Classroom,
 # Account Details, AWC CLI -> Show (Copy and paste the following into ~/.aws/credentials)
@@ -26,15 +26,20 @@ availabilityZone3 = 'us-east-1c'
 
 # AMI ID of Amazon Linux 2 image 64-bit x86 in us-east-1 (can be retrieved, e.g., at
 # https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#LaunchInstanceWizard:)
+# TODO update to recent version of Amazon Linux 2 AMI?
 imageId = 'ami-0d5eff06f840b45e9'
 # for eu-central-1, AMI ID of Amazon Linux 2 would be:
 # imageId = 'ami-0cc293023f983ed53'
 
 # potentially change instanceType to t2.micro for "free tier" if using a regular account
 # for production, t3.nano seams better
-instanceType = 't2.nano'
+# as of SoSe 2022 t2.nano seams to be a bit too low on memory, mariadb first start can fail
+# due to innodb cache out of memory, therefore t2.micro or swap in t2.nano currently recommended
+# instanceType = 't2.nano'
+instanceType = 't2.micro'
 
-keyName = 'srieger-pub'
+# keyName = 'srieger-pub'
+keyName = 'vockey'
 
 
 ################################################################################################
@@ -270,6 +275,7 @@ print("------------------------------------")
 
 response = asClient.create_launch_configuration(
     #IamInstanceProfile='my-iam-role',
+    IamInstanceProfile='EMR_AutoScaling_DefaultRole ',
     ImageId=imageId,
     InstanceType=instanceType,
     LaunchConfigurationName='tug-of-war-asg-launchconfig',
diff --git a/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/create-loadbalancer.py b/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/create-loadbalancer.py
index 2e5f725..98b6c38 100644
--- a/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/create-loadbalancer.py
+++ b/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/create-loadbalancer.py
@@ -26,9 +26,13 @@ imageId = 'ami-0d5eff06f840b45e9'
 
 # potentially change instanceType to t2.micro for "free tier" if using a regular account
 # for production, t3.nano seams better
-instanceType = 't2.nano'
+# as of SoSe 2022 t2.nano seams to be a bit too low on memory, mariadb first start can fail
+# due to innodb cache out of memory, therefore t2.micro or swap in t2.nano currently recommended
+# instanceType = 't2.nano'
+instanceType = 't2.micro'
 
-keyName = 'srieger-pub'
+# keyName = 'srieger-pub'
+keyName = 'vockey'
 
 
 ################################################################################################
diff --git a/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/start-and-add-new-target.py b/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/start-and-add-new-target.py
index 3feb52b..cb96ee1 100644
--- a/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/start-and-add-new-target.py
+++ b/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/start-and-add-new-target.py
@@ -22,15 +22,20 @@ availabilityZone = 'us-east-1b'
 
 # AMI ID of Amazon Linux 2 image 64-bit x86 in us-east-1 (can be retrieved, e.g., at
 # https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#LaunchInstanceWizard:)
+# TODO update to recent version of Amazon Linux 2 AMI?
 imageId = 'ami-0d5eff06f840b45e9'
 # for eu-central-1, AMI ID of Amazon Linux 2 would be:
 # imageId = 'ami-0cc293023f983ed53'
 
 # potentially change instanceType to t2.micro for "free tier" if using a regular account
 # for production, t3.nano seams better
-instanceType = 't2.nano'
+# as of SoSe 2022 t2.nano seams to be a bit too low on memory, mariadb first start can fail
+# due to innodb cache out of memory, therefore t2.micro or swap in t2.nano currently recommended
+# instanceType = 't2.nano'
+instanceType = 't2.micro'
 
-keyName = 'srieger-pub'
+# keyName = 'srieger-pub'
+keyName = 'vockey'
 
 
 ################################################################################################
@@ -125,7 +130,7 @@ for i in range(3, 4):
         time.sleep(1)
         timeout -= 1
     if instance.public_ip_address is not None:
-        print("tug-of-war-in-the-clouds can be accessed at: " + instance.public_ip_address)
+        print("tug-of-war-in-the-clouds can be accessed at: http://" + instance.public_ip_address)
     else:
         print("Could not get public IP using boto3, this is likely an AWS Educate problem. You can however lookup the "
               "public ip from the AWS management console.")
diff --git a/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/start.py b/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/start.py
index f38255c..7600e2f 100644
--- a/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/start.py
+++ b/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/start.py
@@ -22,15 +22,20 @@ availabilityZone = 'us-east-1a'
 
 # AMI ID of Amazon Linux 2 image 64-bit x86 in us-east-1 (can be retrieved, e.g., at
 # https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#LaunchInstanceWizard:)
+# TODO update to recent version of Amazon Linux 2 AMI?
 imageId = 'ami-0d5eff06f840b45e9'
 # for eu-central-1, AMI ID of Amazon Linux 2 would be:
 # imageId = 'ami-0cc293023f983ed53'
 
 # potentially change instanceType to t2.micro for "free tier" if using a regular account
 # for production, t3.nano seams better
-instanceType = 't2.nano'
+# as of SoSe 2022 t2.nano seams to be a bit too low on memory, mariadb first start can fail
+# due to innodb cache out of memory, therefore t2.micro or swap in t2.nano currently recommended
+# instanceType = 't2.nano'
+instanceType = 't2.micro'
 
-keyName = 'srieger-pub'
+# keyName = 'srieger-pub'
+keyName = 'vockey'
 
 
 ################################################################################################
@@ -164,6 +169,8 @@ instanceIdDB = response['Instances'][0]['InstanceId']
 privateIpDB = response['Instances'][0]['PrivateIpAddress']
 # privateIpDB = response['Instances'][0]['NetworkInterfaces'][0]['NetworkInterfaceId']
 
+print("Using private IP to connect to the db: " + privateIpDB);
+
 instance = ec2Resource.Instance(instanceIdDB)
 instance.wait_until_running()
 
@@ -232,7 +239,9 @@ for i in range(1, 3):
         time.sleep(1)
         timeout -= 1
     if instance.public_ip_address is not None:
-        print("tug-of-war-in-the-clouds can be accessed at: " + instance.public_ip_address)
+        print("tug-of-war-in-the-clouds can be accessed at: http://" + instance.public_ip_address)
+        print("Using AWS Academy Lab you should be able to login as shown in the lab README using:")
+        print("ssh -i ~/.ssh/labsuser.pem ec2-user@" + instance.public_ip_address)
     else:
         print("Could not get public IP using boto3, this is likely an AWS Educate problem. You can however lookup the "
               "public ip from the AWS management console.")
-- 
GitLab