Browse Source

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

master
Sebastian Rieger 3 years ago
parent
commit
698ec0a648
  1. 46
      example-projects/tug-of-war-in-the-clouds/aws-boto3-rds-db/start.py
  2. 19
      example-projects/tug-of-war-in-the-clouds/aws-boto3-rds-db/stop.py

46
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("------------------------------------")

19
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'

Loading…
Cancel
Save