did not do part 2. but must complete even if of no use.
BIN
Project-1/Part-2/Project 1-(Part-II)-IaaS.pdf
Normal file
47
Project-1/Part-2/get_info.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import boto3
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
# creds from ~/.aws/credentials
|
||||||
|
session = boto3.Session(profile_name="dev")
|
||||||
|
|
||||||
|
region1="us-east-1"
|
||||||
|
dev_ec2_client = session.client("ec2", region_name=region1)
|
||||||
|
dev_s3_client = session.client("s3", region_name=region1)
|
||||||
|
dev_sqs_client = session.client("sqs", region_name=region1)
|
||||||
|
|
||||||
|
# Get all instances' information
|
||||||
|
all_instances = dev_ec2_client.describe_instances()
|
||||||
|
with open("output.txt", "w") as out_f:
|
||||||
|
pprint(all_instances, stream=out_f)
|
||||||
|
|
||||||
|
print("Capacity Reservations:", len(all_instances["Reservations"]))
|
||||||
|
for idx, reservation in enumerate(all_instances["Reservations"]):
|
||||||
|
print("Reservation", idx + 1, ":-")
|
||||||
|
print("\tGroups:", len(reservation["Groups"])) # TODO: add grp info logging
|
||||||
|
print("\tInstances:", len(reservation["Instances"]))
|
||||||
|
for inst_idx, instance in enumerate(reservation["Instances"]):
|
||||||
|
print("\tInstance", inst_idx + 1, ":-")
|
||||||
|
print("\t\tInstance ID:", instance["InstanceId"])
|
||||||
|
print("\t\tInstance state:", instance["State"]["Name"])
|
||||||
|
print(f"\t\t{instance["InstanceType"]} in {instance["Placement"]["AvailabilityZone"]}")
|
||||||
|
print(f"\t\t{instance["CpuOptions"]["CoreCount"]}vCPU, {instance["Hypervisor"]} hypervisor")
|
||||||
|
print(f"\t\t{instance["PlatformDetails"]} on {instance["RootDeviceType"]} volume")
|
||||||
|
print("\t\tPublic IP address:", instance["PublicIpAddress"] if "PublicIpAddress" in instance else "N/A")
|
||||||
|
|
||||||
|
# Get all buckets' information
|
||||||
|
all_buckets = dev_s3_client.list_buckets()
|
||||||
|
with open("output.txt", "a") as out_f:
|
||||||
|
pprint(all_buckets, stream=out_f)
|
||||||
|
|
||||||
|
print("Buckets:", len(all_buckets["Buckets"]))
|
||||||
|
for bucket in all_buckets["Buckets"]:
|
||||||
|
print("\tName:", bucket["Name"])
|
||||||
|
|
||||||
|
# Get all queues' information
|
||||||
|
all_queues = dev_sqs_client.list_queues()
|
||||||
|
with open("output.txt", "a") as out_f:
|
||||||
|
pprint(all_queues, stream=out_f)
|
||||||
|
|
||||||
|
print("Queues:", len(all_queues["QueueUrls"]))
|
||||||
|
for queue in all_queues["QueueUrls"]:
|
||||||
|
print("\tQueue URL:", queue)
|
||||||
221
Project-1/Part-2/output.txt
Normal file
@ -0,0 +1,221 @@
|
|||||||
|
{'Reservations': [{'Groups': [],
|
||||||
|
'Instances': [{'AmiLaunchIndex': 0,
|
||||||
|
'Architecture': 'x86_64',
|
||||||
|
'BlockDeviceMappings': [{'DeviceName': '/dev/sda1',
|
||||||
|
'Ebs': {'AttachTime': datetime.datetime(2024, 3, 17, 23, 57, 30, tzinfo=tzutc()),
|
||||||
|
'DeleteOnTermination': True,
|
||||||
|
'Status': 'attached',
|
||||||
|
'VolumeId': 'vol-0b9d38863d1b6a517'}}],
|
||||||
|
'CapacityReservationSpecification': {'CapacityReservationPreference': 'open'},
|
||||||
|
'ClientToken': '2460e820-09e2-47f0-b6a2-2bead38887bc',
|
||||||
|
'CpuOptions': {'CoreCount': 1,
|
||||||
|
'ThreadsPerCore': 1},
|
||||||
|
'CurrentInstanceBootMode': 'legacy-bios',
|
||||||
|
'EbsOptimized': False,
|
||||||
|
'EnaSupport': True,
|
||||||
|
'EnclaveOptions': {'Enabled': False},
|
||||||
|
'HibernationOptions': {'Configured': False},
|
||||||
|
'Hypervisor': 'xen',
|
||||||
|
'ImageId': 'ami-05afaa0d246abf7cf',
|
||||||
|
'InstanceId': 'i-000668a9b8c594d20',
|
||||||
|
'InstanceType': 't2.micro',
|
||||||
|
'KeyName': 'cse546-dev',
|
||||||
|
'LaunchTime': datetime.datetime(2024, 3, 17, 23, 57, 30, tzinfo=tzutc()),
|
||||||
|
'MaintenanceOptions': {'AutoRecovery': 'default'},
|
||||||
|
'MetadataOptions': {'HttpEndpoint': 'enabled',
|
||||||
|
'HttpProtocolIpv6': 'disabled',
|
||||||
|
'HttpPutResponseHopLimit': 1,
|
||||||
|
'HttpTokens': 'optional',
|
||||||
|
'InstanceMetadataTags': 'disabled',
|
||||||
|
'State': 'pending'},
|
||||||
|
'Monitoring': {'State': 'disabled'},
|
||||||
|
'NetworkInterfaces': [{'Association': {'IpOwnerId': 'amazon',
|
||||||
|
'PublicDnsName': 'ec2-54-226-176-42.compute-1.amazonaws.com',
|
||||||
|
'PublicIp': '54.226.176.42'},
|
||||||
|
'Attachment': {'AttachTime': datetime.datetime(2024, 3, 17, 23, 57, 30, tzinfo=tzutc()),
|
||||||
|
'AttachmentId': 'eni-attach-07debb5dda48fe9e1',
|
||||||
|
'DeleteOnTermination': True,
|
||||||
|
'DeviceIndex': 0,
|
||||||
|
'NetworkCardIndex': 0,
|
||||||
|
'Status': 'attached'},
|
||||||
|
'Description': '',
|
||||||
|
'Groups': [{'GroupId': 'sg-019686b391a1be806',
|
||||||
|
'GroupName': 'default'}],
|
||||||
|
'InterfaceType': 'interface',
|
||||||
|
'Ipv6Addresses': [],
|
||||||
|
'MacAddress': '0a:ff:f3:35:32:df',
|
||||||
|
'NetworkInterfaceId': 'eni-061ec190f81f40db0',
|
||||||
|
'OwnerId': '146064153251',
|
||||||
|
'PrivateDnsName': 'ip-172-31-30-6.ec2.internal',
|
||||||
|
'PrivateIpAddress': '172.31.30.6',
|
||||||
|
'PrivateIpAddresses': [{'Association': {'IpOwnerId': 'amazon',
|
||||||
|
'PublicDnsName': 'ec2-54-226-176-42.compute-1.amazonaws.com',
|
||||||
|
'PublicIp': '54.226.176.42'},
|
||||||
|
'Primary': True,
|
||||||
|
'PrivateDnsName': 'ip-172-31-30-6.ec2.internal',
|
||||||
|
'PrivateIpAddress': '172.31.30.6'}],
|
||||||
|
'SourceDestCheck': True,
|
||||||
|
'Status': 'in-use',
|
||||||
|
'SubnetId': 'subnet-08c8975406f48de21',
|
||||||
|
'VpcId': 'vpc-0248a892aa9493bd8'}],
|
||||||
|
'Placement': {'AvailabilityZone': 'us-east-1b',
|
||||||
|
'GroupName': '',
|
||||||
|
'Tenancy': 'default'},
|
||||||
|
'PlatformDetails': 'Linux/UNIX',
|
||||||
|
'PrivateDnsName': 'ip-172-31-30-6.ec2.internal',
|
||||||
|
'PrivateDnsNameOptions': {'EnableResourceNameDnsAAAARecord': False,
|
||||||
|
'EnableResourceNameDnsARecord': False,
|
||||||
|
'HostnameType': 'ip-name'},
|
||||||
|
'PrivateIpAddress': '172.31.30.6',
|
||||||
|
'ProductCodes': [],
|
||||||
|
'PublicDnsName': 'ec2-54-226-176-42.compute-1.amazonaws.com',
|
||||||
|
'PublicIpAddress': '54.226.176.42',
|
||||||
|
'RootDeviceName': '/dev/sda1',
|
||||||
|
'RootDeviceType': 'ebs',
|
||||||
|
'SecurityGroups': [{'GroupId': 'sg-019686b391a1be806',
|
||||||
|
'GroupName': 'default'}],
|
||||||
|
'SourceDestCheck': True,
|
||||||
|
'State': {'Code': 32,
|
||||||
|
'Name': 'shutting-down'},
|
||||||
|
'StateReason': {'Code': 'Client.UserInitiatedShutdown',
|
||||||
|
'Message': 'Client.UserInitiatedShutdown: '
|
||||||
|
'User initiated '
|
||||||
|
'shutdown'},
|
||||||
|
'StateTransitionReason': 'User initiated '
|
||||||
|
'(2024-03-18 '
|
||||||
|
'05:12:55 GMT)',
|
||||||
|
'SubnetId': 'subnet-08c8975406f48de21',
|
||||||
|
'Tags': [{'Key': 'Name',
|
||||||
|
'Value': 'app-tier-instance'}],
|
||||||
|
'UsageOperation': 'RunInstances',
|
||||||
|
'UsageOperationUpdateTime': datetime.datetime(2024, 3, 17, 23, 57, 30, tzinfo=tzutc()),
|
||||||
|
'VirtualizationType': 'hvm',
|
||||||
|
'VpcId': 'vpc-0248a892aa9493bd8'}],
|
||||||
|
'OwnerId': '146064153251',
|
||||||
|
'ReservationId': 'r-037c5b8ea7529f040'},
|
||||||
|
{'Groups': [],
|
||||||
|
'Instances': [{'AmiLaunchIndex': 0,
|
||||||
|
'Architecture': 'x86_64',
|
||||||
|
'BlockDeviceMappings': [{'DeviceName': '/dev/sda1',
|
||||||
|
'Ebs': {'AttachTime': datetime.datetime(2024, 3, 18, 5, 13, 9, tzinfo=tzutc()),
|
||||||
|
'DeleteOnTermination': True,
|
||||||
|
'Status': 'attaching',
|
||||||
|
'VolumeId': 'vol-09f549973ead49491'}}],
|
||||||
|
'CapacityReservationSpecification': {'CapacityReservationPreference': 'open'},
|
||||||
|
'ClientToken': '303fb65a-631d-468a-aea3-77a34152b976',
|
||||||
|
'CpuOptions': {'CoreCount': 1,
|
||||||
|
'ThreadsPerCore': 1},
|
||||||
|
'CurrentInstanceBootMode': 'legacy-bios',
|
||||||
|
'EbsOptimized': False,
|
||||||
|
'EnaSupport': True,
|
||||||
|
'EnclaveOptions': {'Enabled': False},
|
||||||
|
'HibernationOptions': {'Configured': False},
|
||||||
|
'Hypervisor': 'xen',
|
||||||
|
'ImageId': 'ami-0c7217cdde317cfec',
|
||||||
|
'InstanceId': 'i-001fcad9b4bda4cbe',
|
||||||
|
'InstanceType': 't2.micro',
|
||||||
|
'KeyName': 'cse546-dev',
|
||||||
|
'LaunchTime': datetime.datetime(2024, 3, 18, 5, 13, 8, tzinfo=tzutc()),
|
||||||
|
'MaintenanceOptions': {'AutoRecovery': 'default'},
|
||||||
|
'MetadataOptions': {'HttpEndpoint': 'enabled',
|
||||||
|
'HttpProtocolIpv6': 'disabled',
|
||||||
|
'HttpPutResponseHopLimit': 1,
|
||||||
|
'HttpTokens': 'optional',
|
||||||
|
'InstanceMetadataTags': 'disabled',
|
||||||
|
'State': 'pending'},
|
||||||
|
'Monitoring': {'State': 'disabled'},
|
||||||
|
'NetworkInterfaces': [{'Association': {'IpOwnerId': 'amazon',
|
||||||
|
'PublicDnsName': 'ec2-54-167-113-39.compute-1.amazonaws.com',
|
||||||
|
'PublicIp': '54.167.113.39'},
|
||||||
|
'Attachment': {'AttachTime': datetime.datetime(2024, 3, 18, 5, 13, 8, tzinfo=tzutc()),
|
||||||
|
'AttachmentId': 'eni-attach-0aac12b5548bcf9fc',
|
||||||
|
'DeleteOnTermination': True,
|
||||||
|
'DeviceIndex': 0,
|
||||||
|
'NetworkCardIndex': 0,
|
||||||
|
'Status': 'attaching'},
|
||||||
|
'Description': '',
|
||||||
|
'Groups': [{'GroupId': 'sg-019686b391a1be806',
|
||||||
|
'GroupName': 'default'}],
|
||||||
|
'InterfaceType': 'interface',
|
||||||
|
'Ipv6Addresses': [],
|
||||||
|
'MacAddress': '0a:ff:d6:7b:8c:b7',
|
||||||
|
'NetworkInterfaceId': 'eni-073f511c623a388ac',
|
||||||
|
'OwnerId': '146064153251',
|
||||||
|
'PrivateDnsName': 'ip-172-31-31-11.ec2.internal',
|
||||||
|
'PrivateIpAddress': '172.31.31.11',
|
||||||
|
'PrivateIpAddresses': [{'Association': {'IpOwnerId': 'amazon',
|
||||||
|
'PublicDnsName': 'ec2-54-167-113-39.compute-1.amazonaws.com',
|
||||||
|
'PublicIp': '54.167.113.39'},
|
||||||
|
'Primary': True,
|
||||||
|
'PrivateDnsName': 'ip-172-31-31-11.ec2.internal',
|
||||||
|
'PrivateIpAddress': '172.31.31.11'}],
|
||||||
|
'SourceDestCheck': True,
|
||||||
|
'Status': 'in-use',
|
||||||
|
'SubnetId': 'subnet-08c8975406f48de21',
|
||||||
|
'VpcId': 'vpc-0248a892aa9493bd8'}],
|
||||||
|
'Placement': {'AvailabilityZone': 'us-east-1b',
|
||||||
|
'GroupName': '',
|
||||||
|
'Tenancy': 'default'},
|
||||||
|
'PlatformDetails': 'Linux/UNIX',
|
||||||
|
'PrivateDnsName': 'ip-172-31-31-11.ec2.internal',
|
||||||
|
'PrivateDnsNameOptions': {'EnableResourceNameDnsAAAARecord': False,
|
||||||
|
'EnableResourceNameDnsARecord': False,
|
||||||
|
'HostnameType': 'ip-name'},
|
||||||
|
'PrivateIpAddress': '172.31.31.11',
|
||||||
|
'ProductCodes': [],
|
||||||
|
'PublicDnsName': 'ec2-54-167-113-39.compute-1.amazonaws.com',
|
||||||
|
'PublicIpAddress': '54.167.113.39',
|
||||||
|
'RootDeviceName': '/dev/sda1',
|
||||||
|
'RootDeviceType': 'ebs',
|
||||||
|
'SecurityGroups': [{'GroupId': 'sg-019686b391a1be806',
|
||||||
|
'GroupName': 'default'}],
|
||||||
|
'SourceDestCheck': True,
|
||||||
|
'State': {'Code': 0, 'Name': 'pending'},
|
||||||
|
'StateTransitionReason': '',
|
||||||
|
'SubnetId': 'subnet-08c8975406f48de21',
|
||||||
|
'Tags': [{'Key': 'Name',
|
||||||
|
'Value': 'web-instance'}],
|
||||||
|
'UsageOperation': 'RunInstances',
|
||||||
|
'UsageOperationUpdateTime': datetime.datetime(2024, 3, 18, 5, 13, 8, tzinfo=tzutc()),
|
||||||
|
'VirtualizationType': 'hvm',
|
||||||
|
'VpcId': 'vpc-0248a892aa9493bd8'}],
|
||||||
|
'OwnerId': '146064153251',
|
||||||
|
'ReservationId': 'r-0678419e9bba10da6'}],
|
||||||
|
'ResponseMetadata': {'HTTPHeaders': {'cache-control': 'no-cache, no-store',
|
||||||
|
'content-type': 'text/xml;charset=UTF-8',
|
||||||
|
'date': 'Mon, 18 Mar 2024 05:13:14 GMT',
|
||||||
|
'server': 'AmazonEC2',
|
||||||
|
'strict-transport-security': 'max-age=31536000; '
|
||||||
|
'includeSubDomains',
|
||||||
|
'transfer-encoding': 'chunked',
|
||||||
|
'vary': 'accept-encoding',
|
||||||
|
'x-amzn-requestid': 'a1fff5d0-40e6-4c66-b06a-3d2a3f22800c'},
|
||||||
|
'HTTPStatusCode': 200,
|
||||||
|
'RequestId': 'a1fff5d0-40e6-4c66-b06a-3d2a3f22800c',
|
||||||
|
'RetryAttempts': 0}}
|
||||||
|
{'Buckets': [{'CreationDate': datetime.datetime(2024, 3, 17, 23, 17, 37, tzinfo=tzutc()),
|
||||||
|
'Name': '1229569564-in-bucket'},
|
||||||
|
{'CreationDate': datetime.datetime(2024, 3, 17, 23, 18, 24, tzinfo=tzutc()),
|
||||||
|
'Name': '1229569564-out-bucket'}],
|
||||||
|
'Owner': {'DisplayName': 'rknarayan02',
|
||||||
|
'ID': 'd9dd1c35ead8c3223e43ab9d0c96cce689c3295fd2799e8c9076d272a36d85a8'},
|
||||||
|
'ResponseMetadata': {'HTTPHeaders': {'content-type': 'application/xml',
|
||||||
|
'date': 'Mon, 18 Mar 2024 05:13:17 GMT',
|
||||||
|
'server': 'AmazonS3',
|
||||||
|
'transfer-encoding': 'chunked',
|
||||||
|
'x-amz-id-2': '7gCwSENarAQMBf7ShdAXTiB5NDX/k5uydWL9nivR9D/23H2Ps8nDJVIzh34dJfxPGCEC3X5LpXg=',
|
||||||
|
'x-amz-request-id': 'EEDAR281YM3D3SEC'},
|
||||||
|
'HTTPStatusCode': 200,
|
||||||
|
'HostId': '7gCwSENarAQMBf7ShdAXTiB5NDX/k5uydWL9nivR9D/23H2Ps8nDJVIzh34dJfxPGCEC3X5LpXg=',
|
||||||
|
'RequestId': 'EEDAR281YM3D3SEC',
|
||||||
|
'RetryAttempts': 0}}
|
||||||
|
{'QueueUrls': ['https://sqs.us-east-1.amazonaws.com/146064153251/1229569564-req-queue',
|
||||||
|
'https://sqs.us-east-1.amazonaws.com/146064153251/1229569564-resp-queue'],
|
||||||
|
'ResponseMetadata': {'HTTPHeaders': {'connection': 'keep-alive',
|
||||||
|
'content-length': '427',
|
||||||
|
'content-type': 'text/xml',
|
||||||
|
'date': 'Mon, 18 Mar 2024 05:13:17 GMT',
|
||||||
|
'x-amzn-requestid': 'ab25ecea-b352-5c95-a779-b29b7cffb16a'},
|
||||||
|
'HTTPStatusCode': 200,
|
||||||
|
'RequestId': 'ab25ecea-b352-5c95-a779-b29b7cffb16a',
|
||||||
|
'RetryAttempts': 0}}
|
||||||
4
Project-1/Part-2/requirements.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
boto3
|
||||||
|
numpy
|
||||||
|
pandas
|
||||||
|
requests
|
||||||
24
Project-1/Part-2/run_single_app_tier.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import boto3
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
# creds from ~/.aws/credentials
|
||||||
|
session = boto3.Session(profile_name="dev")
|
||||||
|
dev_ec2_client = session.client("ec2", region_name="us-east-1")
|
||||||
|
|
||||||
|
# Ubuntu Server 22.04 LTS, 8GB SSD on EBS, 64-bit (x86) 1vCPU
|
||||||
|
# pip installed, torch installed, model loaded
|
||||||
|
app_tier_ami_id = "ami-05afaa0d246abf7cf"
|
||||||
|
reservation = dev_ec2_client.run_instances(
|
||||||
|
ImageId=app_tier_ami_id,
|
||||||
|
InstanceType="t2.micro",
|
||||||
|
KeyName='cse546-dev',
|
||||||
|
MinCount=1,
|
||||||
|
MaxCount=1,
|
||||||
|
TagSpecifications=[
|
||||||
|
{"ResourceType": "instance", "Tags": [{"Key": "Name", "Value": "app-tier-instance"}]}
|
||||||
|
],
|
||||||
|
# UserData=user_data
|
||||||
|
)
|
||||||
|
|
||||||
|
print("Instances allocated successfully:", "Yes" if reservation else "No")
|
||||||
44
Project-1/Part-2/run_web_tier.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import boto3
|
||||||
|
import argparse
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("--eip-id", type=str,help="Allocation ID of elastic IP address")
|
||||||
|
args = vars(parser.parse_args())
|
||||||
|
eip_id = str(args["eip-id"]) if args.get("eip-id") else None
|
||||||
|
|
||||||
|
# creds from ~/.aws/credentials
|
||||||
|
session = boto3.Session(profile_name="dev")
|
||||||
|
dev_ec2_client = session.client("ec2", region_name="us-east-1")
|
||||||
|
|
||||||
|
with open(Path(__file__) / ".." / "web_tier_instance_run", "r") as setup_f:
|
||||||
|
user_data = setup_f.read()
|
||||||
|
|
||||||
|
# Create capacity reservation of instances
|
||||||
|
ami_id = "ami-0c7217cdde317cfec" # Ubuntu Server 22.04 LTS, 8GB SSD on EBS, 64-bit (x86) 1vCPU
|
||||||
|
reservation = dev_ec2_client.run_instances(
|
||||||
|
ImageId=ami_id,
|
||||||
|
InstanceType="t2.micro",
|
||||||
|
KeyName='cse546-dev',
|
||||||
|
MinCount=1, # if available instances are less than min_count, abort with no allocation
|
||||||
|
MaxCount=1, # try to allocate max_count instances. we only need one for now
|
||||||
|
TagSpecifications=[
|
||||||
|
{"ResourceType": "instance", "Tags": [{"Key": "Name", "Value": "web-instance"}]}
|
||||||
|
],
|
||||||
|
# UserData=user_data
|
||||||
|
)
|
||||||
|
|
||||||
|
print("Instances allocated successfully:", "Yes" if reservation else "No")
|
||||||
|
new_inst_id = ''
|
||||||
|
|
||||||
|
# Allocate EIP on successful instance launch
|
||||||
|
if reservation and eip_id is not None:
|
||||||
|
print("Waiting for instance to start running...")
|
||||||
|
waiter = dev_ec2_client.get_waiter('instance_running')
|
||||||
|
waiter.wait(InstanceIds=[new_inst_id])
|
||||||
|
assoc = dev_ec2_client.associate_address(
|
||||||
|
AllocationId=eip_id,
|
||||||
|
InstanceId=new_inst_id
|
||||||
|
)
|
||||||
|
if assoc["ResponseMetadata"]["HTTPStatusCode"] == 200:
|
||||||
|
print("Allocated EIP successfully")
|
||||||
94
Project-1/Part-2/terminate_setup.py
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
import boto3
|
||||||
|
import botocore
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument(
|
||||||
|
"--web-instance-name",
|
||||||
|
type=str,
|
||||||
|
help="Value of 'Name' tag of the web tier instance to be terminated",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--in-bucket-name",
|
||||||
|
type=str,
|
||||||
|
help="Value of 'Name' tag of the S3 input bucket to be terminated",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--out-bucket-name",
|
||||||
|
type=str,
|
||||||
|
help="Value of 'Name' tag of the S3 output bucket to be terminated",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--in-queue-name",
|
||||||
|
type=str,
|
||||||
|
help="Value of 'Name' tag of the SQS request queue to be terminated",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--out-queue-name",
|
||||||
|
type=str,
|
||||||
|
help="Value of 'Name' tag of the SQS response queue to be terminated",
|
||||||
|
)
|
||||||
|
args = vars(parser.parse_args())
|
||||||
|
|
||||||
|
|
||||||
|
def noneparser(obj, key):
|
||||||
|
return str(obj[key]) if obj.get(key) else None
|
||||||
|
|
||||||
|
|
||||||
|
target_web_instance_name = noneparser(args, "web_instance_name")
|
||||||
|
target_in_bucket_name = noneparser(args, "in_bucket_name")
|
||||||
|
target_out_bucket_name = noneparser(args, "out_bucket_name")
|
||||||
|
target_in_queue_name = noneparser(args, "in_queue_name")
|
||||||
|
target_out_queue_name = noneparser(args, "out_queue_name")
|
||||||
|
|
||||||
|
print(
|
||||||
|
target_web_instance_name,
|
||||||
|
target_in_bucket_name,
|
||||||
|
target_out_bucket_name,
|
||||||
|
target_in_queue_name,
|
||||||
|
target_out_queue_name,
|
||||||
|
)
|
||||||
|
|
||||||
|
# creds from ~/.aws/credentials
|
||||||
|
session = boto3.Session(profile_name="dev")
|
||||||
|
|
||||||
|
region1 = "us-east-1"
|
||||||
|
dev_ec2_client = session.client("ec2", region_name=region1)
|
||||||
|
dev_s3_client = session.client("s3", region_name=region1)
|
||||||
|
|
||||||
|
|
||||||
|
def get_instance_id_by_name_tag(name):
|
||||||
|
all_instances = dev_ec2_client.describe_instances()
|
||||||
|
for reservation in all_instances["Reservations"]:
|
||||||
|
for instance in reservation["Instances"]:
|
||||||
|
for tag in instance["Tags"]:
|
||||||
|
if tag["Key"] == "Name" and tag["Value"] == name:
|
||||||
|
return instance["InstanceId"]
|
||||||
|
return -1
|
||||||
|
|
||||||
|
# web tier
|
||||||
|
if target_web_instance_name is not None:
|
||||||
|
target_inst_id = get_instance_id_by_name_tag(target_web_instance_name)
|
||||||
|
if target_inst_id == -1:
|
||||||
|
print("Instance does not exist")
|
||||||
|
else:
|
||||||
|
print("Found web-instance ID: ", target_inst_id)
|
||||||
|
response = dev_ec2_client.terminate_instances(InstanceIds=[target_inst_id])
|
||||||
|
if response["ResponseMetadata"]["HTTPStatusCode"] == 200:
|
||||||
|
print("Terminated instance successfully")
|
||||||
|
|
||||||
|
# buckets
|
||||||
|
if target_in_bucket_name is not None:
|
||||||
|
try:
|
||||||
|
response = dev_s3_client.delete_bucket(Bucket=target_in_bucket_name)
|
||||||
|
if response["ResponseMetadata"]["HTTPStatusCode"] == 204:
|
||||||
|
print("Deleted input bucket successfully")
|
||||||
|
except dev_s3_client.exceptions.NoSuchBucket as e:
|
||||||
|
print("Input bucket does not exist")
|
||||||
|
if target_out_bucket_name is not None:
|
||||||
|
try:
|
||||||
|
response = dev_s3_client.delete_bucket(Bucket=target_out_bucket_name)
|
||||||
|
if response["ResponseMetadata"]["HTTPStatusCode"] == 204:
|
||||||
|
print("Deleted output bucket successfully")
|
||||||
|
except dev_s3_client.exceptions.NoSuchBucket as e:
|
||||||
|
print("Output bucket does not exist")
|
||||||
4
Project-1/Part-2/web-tier-express/README.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Web tier with ExpressJS
|
||||||
|
|
||||||
|
- Run `npm i` to install all dependencies
|
||||||
|
- Start: `npm run dev` or `prod`
|
||||||
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |