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 40185e1..ec66a27 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 @@ -1,19 +1,38 @@ import boto3 from botocore.exceptions import ClientError + +################################################################################################ +# +# Configuration Parameters +# +################################################################################################ + + region = 'eu-central-1' availabilityZone = 'eu-central-1b' +vpc_id = 'vpc-eedd4187' subnet1 = 'subnet-41422b28' subnet2 = 'subnet-5c5f6d16' subnet3 = 'subnet-6f2ea214' +# if you only have one VPC, vpc_id can be retrieved using: +# +# response = ec2Client.describe_vpcs() +# vpc_id = response.get('Vpcs', [{}])[0].get('VpcId', '') + + +################################################################################################ +# +# boto3 code +# +################################################################################################ + + client = boto3.setup_default_session(region_name=region) ec2Client = boto3.client("ec2") ec2Resource = boto3.resource('ec2') -response = ec2Client.describe_vpcs() -vpc_id = response.get('Vpcs', [{}])[0].get('VpcId', '') - response = ec2Client.describe_security_groups(Filters=[{'Name': 'group-name', 'Values': ['tug-of-war']}]) security_group_id = response.get('SecurityGroups', [{}])[0].get('GroupId', '') 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 19d221d..8364043 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 @@ -1,20 +1,38 @@ import boto3 from botocore.exceptions import ClientError + +################################################################################################ +# +# Configuration Parameters +# +################################################################################################ + + region = 'eu-central-1' availabilityZone = 'eu-central-1b' +vpc_id = 'vpc-eedd4187' imageId = 'ami-0cc293023f983ed53' instanceType = 't3.nano' keyName = 'srieger-pub' +# if you only have one VPC, vpc_id can be retrieved using: +# +# response = ec2Client.describe_vpcs() +# vpc_id = response.get('Vpcs', [{}])[0].get('VpcId', '') + + +################################################################################################ +# +# boto3 code +# +################################################################################################ + client = boto3.setup_default_session(region_name=region) ec2Client = boto3.client("ec2") ec2Resource = boto3.resource('ec2') -response = ec2Client.describe_vpcs() -vpc_id = response.get('Vpcs', [{}])[0].get('VpcId', '') - elbv2Client = boto3.client('elbv2') response = ec2Client.describe_security_groups(Filters=[{'Name': 'group-name', 'Values': ['tug-of-war']}]) 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 bf81d05..3a2ae04 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 @@ -1,39 +1,38 @@ import boto3 from botocore.exceptions import ClientError + +################################################################################################ +# +# Configuration Parameters +# +################################################################################################ + + region = 'eu-central-1' availabilityZone = 'eu-central-1b' +vpc_id = 'vpc-eedd4187' imageId = 'ami-0cc293023f983ed53' instanceType = 't3.nano' keyName = 'srieger-pub' -userDataDB = ('#!/bin/bash\n' - '#!/bin/bash\n' - '# extra repo for RedHat rpms\n' - 'yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm\n' - '# essential tools\n' - 'yum install -y joe htop git\n' - '# mysql\n' - 'yum install -y mariadb mariadb-server\n' - '\n' - 'service mariadb start\n' - '\n' - 'echo "create database cloud_tug_of_war" | mysql -u root\n' - '\n' - 'echo "create table clouds ( cloud_id INT AUTO_INCREMENT, name VARCHAR(255) NOT NULL, value INT, max_value INT, PRIMARY KEY (cloud_id))" | mysql -u root cloud_tug_of_war\n' - '\n' - 'echo "CREATE USER \'cloud_tug_of_war\'@\'%\' IDENTIFIED BY \'cloudpass\';" | mysql -u root\n' - 'echo "GRANT ALL PRIVILEGES ON cloud_tug_of_war.* TO \'cloud_tug_of_war\'@\'%\';" | mysql -u root\n' - 'echo "FLUSH PRIVILEGES" | mysql -u root\n' - ) -# convert with: cat install-mysql | sed "s/^/'/; s/$/\\\n'/" +# if you only have one VPC, vpc_id can be retrieved using: +# +# response = ec2Client.describe_vpcs() +# vpc_id = response.get('Vpcs', [{}])[0].get('VpcId', '') + + +################################################################################################ +# +# boto3 code +# +################################################################################################ + client = boto3.setup_default_session(region_name=region) ec2Client = boto3.client("ec2") ec2Resource = boto3.resource('ec2') -response = ec2Client.describe_vpcs() -vpc_id = response.get('Vpcs', [{}])[0].get('VpcId', '') subnet_id = ec2Client.describe_subnets( Filters=[ { @@ -97,6 +96,28 @@ try: except ClientError as e: print(e) + +userDataDB = ('#!/bin/bash\n' + '#!/bin/bash\n' + '# extra repo for RedHat rpms\n' + 'yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm\n' + '# essential tools\n' + 'yum install -y joe htop git\n' + '# mysql\n' + 'yum install -y mariadb mariadb-server\n' + '\n' + 'service mariadb start\n' + '\n' + 'echo "create database cloud_tug_of_war" | mysql -u root\n' + '\n' + 'echo "create table clouds ( cloud_id INT AUTO_INCREMENT, name VARCHAR(255) NOT NULL, value INT, max_value INT, PRIMARY KEY (cloud_id))" | mysql -u root cloud_tug_of_war\n' + '\n' + 'echo "CREATE USER \'cloud_tug_of_war\'@\'%\' IDENTIFIED BY \'cloudpass\';" | mysql -u root\n' + 'echo "GRANT ALL PRIVILEGES ON cloud_tug_of_war.* TO \'cloud_tug_of_war\'@\'%\';" | mysql -u root\n' + 'echo "FLUSH PRIVILEGES" | mysql -u root\n' + ) +# convert user-data from script with: cat install-mysql | sed "s/^/'/; s/$/\\\n'/" + print("Running new DB instance...") print("------------------------------------") diff --git a/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/stop.py b/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/stop.py index bcfbac2..3fe5d5e 100644 --- a/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/stop.py +++ b/example-projects/tug-of-war-in-the-clouds/aws-boto3-standalone-db/stop.py @@ -2,15 +2,34 @@ import time import boto3 from botocore.exceptions import ClientError + +################################################################################################ +# +# Configuration Parameters +# +################################################################################################ + + region = 'eu-central-1' +vpc_id = 'vpc-eedd4187' + +# if you only have one VPC, vpc_id can be retrieved using: +# +# response = ec2Client.describe_vpcs() +# vpc_id = response.get('Vpcs', [{}])[0].get('VpcId', '') + + +################################################################################################ +# +# boto3 code +# +################################################################################################ + client = boto3.setup_default_session(region_name=region) ec2Client = boto3.client("ec2") ec2Resource = boto3.resource('ec2') -response = ec2Client.describe_vpcs() -vpc_id = response.get('Vpcs', [{}])[0].get('VpcId', '') - elbv2Client = boto3.client('elbv2') print("Deleting load balancer and deps...")