From 698ec0a648cb0c92a081965246ab8d9b1a6872ca Mon Sep 17 00:00:00 2001 From: Sebastian Rieger Date: Tue, 1 Jun 2021 13:17:36 +0200 Subject: [PATCH] adapted aws-boto3-rds-db example of tug-of-war in the clouds to AWS Educate Accounts, however, RDS is not allowed in our current classroom --- .../aws-boto3-rds-db/start.py | 46 +++++++++++++------ .../aws-boto3-rds-db/stop.py | 19 ++++++-- 2 files changed, 49 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 bdc2e83..49a6796 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 @@ -1,40 +1,54 @@ import boto3 from botocore.exceptions import ClientError - ################################################################################################ # # Configuration Parameters # ################################################################################################ +# !!!!!!!! You cannot use RDS in AWS Ecucate Account !!!!!!!! -region = 'eu-central-1' -availabilityZone = 'eu-central-1b' -vpc_id = 'vpc-eedd4187' -imageId = 'ami-0cc293023f983ed53' -instanceType = 't3.nano' -keyName = 'srieger-pub' +# 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' +availabilityZone = 'us-east-1a' +# 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' ################################################################################################ # -# boto3 code +# boto3 clients and resources (dependencies) # ################################################################################################ - client = boto3.setup_default_session(region_name=region) ec2Client = boto3.client("ec2") ec2Resource = boto3.resource('ec2') rdsClient = boto3.client("rds") +# 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_id = ec2Client.describe_subnets( Filters=[ { @@ -42,6 +56,12 @@ subnet_id = ec2Client.describe_subnets( } ])['Subnets'][0]['SubnetId'] +################################################################################################ +# +# boto3 code to deploy the application +# +################################################################################################ + print("Deleting old instance...") print("------------------------------------") diff --git a/example-projects/tug-of-war-in-the-clouds/aws-boto3-rds-db/stop.py b/example-projects/tug-of-war-in-the-clouds/aws-boto3-rds-db/stop.py index 534fa92..53c2654 100644 --- a/example-projects/tug-of-war-in-the-clouds/aws-boto3-rds-db/stop.py +++ b/example-projects/tug-of-war-in-the-clouds/aws-boto3-rds-db/stop.py @@ -9,9 +9,22 @@ from botocore.exceptions import ClientError ################################################################################################ -region = 'eu-central-1' -availabilityZone = 'eu-central-1b' -imageId = 'ami-0cc293023f983ed53' +# 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) + +# changed to use us-east, to be able to use AWS Educate Classroom +region = 'us-east-1' +availabilityZone = 'us-east-1a' +# 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 instanceType = 't3.nano' keyName = 'srieger-pub'