Skip to content

Commit

Permalink
modules completed
Browse files Browse the repository at this point in the history
  • Loading branch information
sidhu2003 committed May 12, 2024
1 parent 549881f commit 4ac4d0a
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 0 deletions.
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ def main():
print(ascii_art)
if __name__ == "__main__":
main()

14 changes: 14 additions & 0 deletions modules/EC2/ec2_create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import boto3 as bt

ec2 = bt.resource('ec2')

def create_instance(ami_id, min_count, max_count, instance_type, key_name):
instances = ec2.create_instances(
ImageId=ami_id,
MinCount=min_count,
MaxCount=max_count,
InstanceType=instance_type,
KeyName=key_name
)

print(instances + " instances are launched successfully")
Empty file removed modules/EC2/ec2_delete.py
Empty file.
12 changes: 12 additions & 0 deletions modules/EC2/ec2_describe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import boto3 as bt

client = bt.client('ec2')

def describe_instance(instance_id):
response = client.describe_instances(
InstanceIds=[
instance_id,
],
)

print(response)
11 changes: 11 additions & 0 deletions modules/EC2/ec2_stop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import boto3 as bt

client = bt.client('ec2')

def stop_instance(instance_id):
response = client.stop_instances(
InstanceIds=[
instance_id,
],
)
print(response)
7 changes: 7 additions & 0 deletions modules/KeyPairs/create_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import boto3

ec2 = boto3.client('ec2')

def create_key_pair(key_name):
response = ec2.create_key_pair(KeyName=key_name)
print(response)
7 changes: 7 additions & 0 deletions modules/KeyPairs/delete_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import boto3 as bt

ec2 = bt.resource('ec2')

def delete_key_pair(key_name):
response = ec2.delete_key_pair(KeyName=key_name)
print(response)
7 changes: 7 additions & 0 deletions modules/KeyPairs/describe_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import boto3 as bt

ec2 = bt.resource('ec2')

def describe_key_pair(key_name):
response = ec2.describe_key_pairs(KeyNames=[key_name])
print(response)
39 changes: 39 additions & 0 deletions modules/SecurityGrp/create_secgrp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import boto3
from botocore.exceptions import ClientError

ec2 = boto3.client('ec2')

def create_security_group(vpc_id, group_name, description):
try:
response = ec2.create_security_group(
GroupName=group_name,
Description=description,
VpcId=vpc_id
)
security_group_id = response['GroupId']
print('Security Group Created %s in vpc %s.' % (security_group_id, vpc_id))

data = ec2.authorize_security_group_ingress(
GroupId=security_group_id,
IpPermissions=[
{
'IpProtocol': 'tcp',
'FromPort': 80,
'ToPort': 80,
'IpRanges': [{'CidrIp': '0.0.0.0/0'}]
},
{
'IpProtocol': 'tcp',
'FromPort': 22,
'ToPort': 22,
'IpRanges': [{'CidrIp': '0.0.0.0/0'}]
}
]
)
print('Ingress Successfully Set %s' % data)
except ClientError as e:
print(e)




9 changes: 9 additions & 0 deletions modules/SecurityGrp/delete_secgrp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import boto3 as bt

ec2 = bt.resource('ec2')

def delete_security_group(group_id, group_name):
response = ec2.delete_security_group(
GroupId=group_id,
GroupName=group_name,
)
11 changes: 11 additions & 0 deletions modules/SecurityGrp/describe_secgrp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import boto3 as bt

client = bt.client('ec2')

def describe_security_group(group_id):
response = client.describe_security_groups(
GroupIds=[
group_id,
],
)
print(response)

0 comments on commit 4ac4d0a

Please sign in to comment.