|
@ -7,17 +7,28 @@ import boto3 |
|
|
################################################################################################ |
|
|
################################################################################################ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
region = 'eu-central-1' |
|
|
|
|
|
availabilityZone = 'eu-central-1b' |
|
|
|
|
|
vpc_id = 'vpc-eedd4187' |
|
|
|
|
|
subnet1 = 'subnet-41422b28' |
|
|
|
|
|
subnet2 = 'subnet-5c5f6d16' |
|
|
|
|
|
subnet3 = 'subnet-6f2ea214' |
|
|
|
|
|
|
|
|
# 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) |
|
|
|
|
|
|
|
|
# if you only have one VPC, vpc_id can be retrieved using: |
|
|
|
|
|
# |
|
|
|
|
|
# response = ec2Client.describe_vpcs() |
|
|
|
|
|
# vpc_id = response.get('Vpcs', [{}])[0].get('VpcId', '') |
|
|
|
|
|
|
|
|
# changed to use us-east, to be able to use AWS Educate Classroom |
|
|
|
|
|
region = 'us-east-1' |
|
|
|
|
|
availabilityZone1 = 'us-east-1a' |
|
|
|
|
|
availabilityZone2 = 'us-east-1b' |
|
|
|
|
|
availabilityZone3 = 'us-east-1c' |
|
|
|
|
|
# region = 'eu-central-1' |
|
|
|
|
|
# availabilityZone = 'eu-central-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:) |
|
|
|
|
|
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' |
|
|
|
|
|
|
|
|
|
|
|
keyName = 'srieger-pub' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
################################################################################################ |
|
|
################################################################################################ |
|
@ -31,6 +42,35 @@ client = boto3.setup_default_session(region_name=region) |
|
|
ec2Client = boto3.client("ec2") |
|
|
ec2Client = boto3.client("ec2") |
|
|
ec2Resource = boto3.resource('ec2') |
|
|
ec2Resource = boto3.resource('ec2') |
|
|
|
|
|
|
|
|
|
|
|
# if you only have one VPC, vpc_id can be retrieved using: |
|
|
|
|
|
response = ec2Client.describe_vpcs() |
|
|
|
|
|
vpc_id = response.get('Vpcs', [{}])[0].get('VpcId', '') |
|
|
|
|
|
# if you have more than one VPC, vpc_id should be specified, and code |
|
|
|
|
|
# top retrieve VPC id below needs to be commented out |
|
|
|
|
|
# vpc_id = 'vpc-eedd4187' |
|
|
|
|
|
|
|
|
|
|
|
subnet_id1 = ec2Client.describe_subnets( |
|
|
|
|
|
Filters=[ |
|
|
|
|
|
{ |
|
|
|
|
|
'Name': 'availability-zone', 'Values': [availabilityZone1] |
|
|
|
|
|
} |
|
|
|
|
|
])['Subnets'][0]['SubnetId'] |
|
|
|
|
|
|
|
|
|
|
|
subnet_id2 = ec2Client.describe_subnets( |
|
|
|
|
|
Filters=[ |
|
|
|
|
|
{ |
|
|
|
|
|
'Name': 'availability-zone', 'Values': [availabilityZone2] |
|
|
|
|
|
} |
|
|
|
|
|
])['Subnets'][0]['SubnetId'] |
|
|
|
|
|
|
|
|
|
|
|
subnet_id3 = ec2Client.describe_subnets( |
|
|
|
|
|
Filters=[ |
|
|
|
|
|
{ |
|
|
|
|
|
'Name': 'availability-zone', 'Values': [availabilityZone3] |
|
|
|
|
|
} |
|
|
|
|
|
])['Subnets'][0]['SubnetId'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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', '') |
|
|
|
|
|
|
|
@ -39,9 +79,9 @@ elbv2Client = boto3.client('elbv2') |
|
|
response = elbv2Client.create_load_balancer( |
|
|
response = elbv2Client.create_load_balancer( |
|
|
Name='tug-of-war-loadbalancer', |
|
|
Name='tug-of-war-loadbalancer', |
|
|
Subnets=[ |
|
|
Subnets=[ |
|
|
subnet1, |
|
|
|
|
|
subnet2, |
|
|
|
|
|
subnet3, |
|
|
|
|
|
|
|
|
subnet_id1, |
|
|
|
|
|
subnet_id2, |
|
|
|
|
|
subnet_id3 |
|
|
], |
|
|
], |
|
|
SecurityGroups=[ |
|
|
SecurityGroups=[ |
|
|
security_group_id |
|
|
security_group_id |
|
|