Skip to content
Snippets Groups Projects
Commit aa7160f6 authored by Sebastian Rieger's avatar Sebastian Rieger
Browse files

added code section comments, added config param for VPC to support starting in...

added code section comments, added config param for VPC to support starting in envs with multiple vpcs
parent bdd77fed
No related branches found
No related tags found
No related merge requests found
import boto3 import boto3
from botocore.exceptions import ClientError from botocore.exceptions import ClientError
################################################################################################
#
# Configuration Parameters
#
################################################################################################
region = 'eu-central-1' region = 'eu-central-1'
availabilityZone = 'eu-central-1b' availabilityZone = 'eu-central-1b'
vpc_id = 'vpc-eedd4187'
subnet1 = 'subnet-41422b28' subnet1 = 'subnet-41422b28'
subnet2 = 'subnet-5c5f6d16' subnet2 = 'subnet-5c5f6d16'
subnet3 = 'subnet-6f2ea214' 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) client = boto3.setup_default_session(region_name=region)
ec2Client = boto3.client("ec2") ec2Client = boto3.client("ec2")
ec2Resource = boto3.resource('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']}]) response = ec2Client.describe_security_groups(Filters=[{'Name': 'group-name', 'Values': ['tug-of-war']}])
security_group_id = response.get('SecurityGroups', [{}])[0].get('GroupId', '') security_group_id = response.get('SecurityGroups', [{}])[0].get('GroupId', '')
......
import boto3 import boto3
from botocore.exceptions import ClientError from botocore.exceptions import ClientError
################################################################################################
#
# Configuration Parameters
#
################################################################################################
region = 'eu-central-1' region = 'eu-central-1'
availabilityZone = 'eu-central-1b' availabilityZone = 'eu-central-1b'
vpc_id = 'vpc-eedd4187'
imageId = 'ami-0cc293023f983ed53' imageId = 'ami-0cc293023f983ed53'
instanceType = 't3.nano' instanceType = 't3.nano'
keyName = 'srieger-pub' 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) client = boto3.setup_default_session(region_name=region)
ec2Client = boto3.client("ec2") ec2Client = boto3.client("ec2")
ec2Resource = boto3.resource('ec2') ec2Resource = boto3.resource('ec2')
response = ec2Client.describe_vpcs()
vpc_id = response.get('Vpcs', [{}])[0].get('VpcId', '')
elbv2Client = boto3.client('elbv2') elbv2Client = boto3.client('elbv2')
response = ec2Client.describe_security_groups(Filters=[{'Name': 'group-name', 'Values': ['tug-of-war']}]) response = ec2Client.describe_security_groups(Filters=[{'Name': 'group-name', 'Values': ['tug-of-war']}])
......
import boto3 import boto3
from botocore.exceptions import ClientError from botocore.exceptions import ClientError
################################################################################################
#
# Configuration Parameters
#
################################################################################################
region = 'eu-central-1' region = 'eu-central-1'
availabilityZone = 'eu-central-1b' availabilityZone = 'eu-central-1b'
vpc_id = 'vpc-eedd4187'
imageId = 'ami-0cc293023f983ed53' imageId = 'ami-0cc293023f983ed53'
instanceType = 't3.nano' instanceType = 't3.nano'
keyName = 'srieger-pub' 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) client = boto3.setup_default_session(region_name=region)
ec2Client = boto3.client("ec2") ec2Client = boto3.client("ec2")
ec2Resource = boto3.resource('ec2') ec2Resource = boto3.resource('ec2')
response = ec2Client.describe_vpcs()
vpc_id = response.get('Vpcs', [{}])[0].get('VpcId', '')
subnet_id = ec2Client.describe_subnets( subnet_id = ec2Client.describe_subnets(
Filters=[ Filters=[
{ {
...@@ -97,6 +96,28 @@ try: ...@@ -97,6 +96,28 @@ try:
except ClientError as e: except ClientError as e:
print(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("Running new DB instance...")
print("------------------------------------") print("------------------------------------")
......
...@@ -2,15 +2,34 @@ import time ...@@ -2,15 +2,34 @@ import time
import boto3 import boto3
from botocore.exceptions import ClientError from botocore.exceptions import ClientError
################################################################################################
#
# Configuration Parameters
#
################################################################################################
region = 'eu-central-1' 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) client = boto3.setup_default_session(region_name=region)
ec2Client = boto3.client("ec2") ec2Client = boto3.client("ec2")
ec2Resource = boto3.resource('ec2') ec2Resource = boto3.resource('ec2')
response = ec2Client.describe_vpcs()
vpc_id = response.get('Vpcs', [{}])[0].get('VpcId', '')
elbv2Client = boto3.client('elbv2') elbv2Client = boto3.client('elbv2')
print("Deleting load balancer and deps...") print("Deleting load balancer and deps...")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment