Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from avinashkranjan:master #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 71 commits into Uncodedtech:master from avinashkranjan:master
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
92d1043
Merge pull request #1 from avinashkranjan/master
anuragmukherjee2001 Mar 31, 2021
394435b
Create mini google assistant.py
A-kriti Apr 1, 2021
4ee89b3
Create mini google assistant.py
A-kriti Apr 1, 2021
ff6afd0
Create README.md
A-kriti Apr 1, 2021
0943ea1
Add GUI Chat Application
Yuvraj-kadale Apr 3, 2021
e03f323
Added the health log book
anuragmukherjee2001 Apr 5, 2021
3de0844
Updated the README file
anuragmukherjee2001 Apr 5, 2021
d18e30d
Add initial files
Lakhankumawat Apr 8, 2021
55454e0
Add brick game
Yuvraj-kadale Apr 8, 2021
f4e9393
Updating the main.py file
anuragmukherjee2001 Apr 9, 2021
b2c02d4
Creating database.py file
anuragmukherjee2001 Apr 9, 2021
a3db397
Updated the README file
anuragmukherjee2001 Apr 9, 2021
cb892a9
Fix GUI Chat additional files
Yuvraj-kadale Apr 9, 2021
eca9975
fix bugs
Yuvraj-kadale Apr 9, 2021
24101b7
Add Readme
Yuvraj-kadale Apr 9, 2021
de93854
Add Output
Yuvraj-kadale Apr 9, 2021
243f854
Update Brick Breaker game/Readme.md
Yuvraj-kadale Apr 10, 2021
ae9584e
This is my code for issue
shantamsultania Apr 10, 2021
a36439d
Add click to start
Yuvraj-kadale Apr 10, 2021
bb2e590
Merge branch 'brick_game' of https://github.com/Yuvraj-kadale/Amazing...
Yuvraj-kadale Apr 10, 2021
54da987
AWS Scripts for Automation's
shantamsultania Apr 11, 2021
da2d538
Update TicTacToe.py
Lakhankumawat Apr 12, 2021
57b408f
Update TicTacToe.py
Lakhankumawat Apr 12, 2021
02262e4
AWS Automation Script for creating/ Managing Aws Ec2 instances and RDS
shantamsultania Apr 12, 2021
0049b68
AWS Automation testing scripts for AWS Code testing
shantamsultania Apr 12, 2021
5a4a628
Create Fast_Algorithm.py
ShubhamGupta577 Apr 12, 2021
7b9be77
Add files via upload
ShubhamGupta577 Apr 12, 2021
293d6d4
Create Readme.md
ShubhamGupta577 Apr 12, 2021
ed3b65f
Delete mini google assistant.py
A-kriti Apr 13, 2021
8a5364b
Create script.py
tanvi355 Apr 13, 2021
92b7af9
Create README.md
tanvi355 Apr 13, 2021
54351b9
Update Fast Algorithm/Fast_Algorithm.py
ShubhamGupta577 Apr 13, 2021
2beb21e
Requested changes done.
ShubhamGupta577 Apr 13, 2021
361c1a1
Adding guessing game with tkinter code and readme
saidrishya Apr 13, 2021
5d7b8d7
Rename Fast Algorithm/Fast_Algorithm.py to Fast Algorithm (Corner Det...
ShubhamGupta577 Apr 13, 2021
9df4db3
Rename Fast Algorithm/Readme.md to Fast Algorithm (Corner Detection)/...
ShubhamGupta577 Apr 13, 2021
98cb4da
Add files via upload
ShubhamGupta577 Apr 13, 2021
e9cea75
Delete Fast Algorithm directory
ShubhamGupta577 Apr 13, 2021
dff871e
Update Readme.md
ShubhamGupta577 Apr 13, 2021
1bd944e
Update Fast_Algorithm.py
ShubhamGupta577 Apr 13, 2021
31de4f7
scraping implemented
Ayushjain2205 Apr 13, 2021
536ff6f
display script added - to display data from database
Ayushjain2205 Apr 13, 2021
dad4ae2
requirements file added
Ayushjain2205 Apr 13, 2021
c1fbc98
save scraped data in database
Ayushjain2205 Apr 13, 2021
338179b
Readme file added
Ayushjain2205 Apr 13, 2021
86f195c
Updated The main.py file
anuragmukherjee2001 Apr 14, 2021
3afaecf
Update TicTacToe.py
Lakhankumawat Apr 14, 2021
2c84829
Add game over screen
Yuvraj-kadale Apr 14, 2021
15facfe
fix indentation
Yuvraj-kadale Apr 14, 2021
5eb1e2a
Create Mini google assistant.py
A-kriti Apr 14, 2021
d7940af
AWS Management Scripts
shantamsultania Apr 14, 2021
060cb2a
AWS Management Scripts
shantamsultania Apr 14, 2021
7f479f5
Requested changes have been made.
ShubhamGupta577 Apr 14, 2021
9142f41
Update README.md
tanvi355 Apr 15, 2021
a4bce14
Update AWS Management Scripts/AWS Automation Script for AWS endorseme...
shantamsultania Apr 15, 2021
0fd9a3b
Update AWS Management Scripts/AWS Automation Script for AWS endorseme...
shantamsultania Apr 15, 2021
c7fd39a
Update AWS Management Scripts/AWS Automation Script for AWS endorseme...
shantamsultania Apr 15, 2021
c24d1c6
Delete mini google assistant.py
A-kriti Apr 15, 2021
00b9082
changes made
Ayushjain2205 Apr 15, 2021
268c0ef
AWS Management Scripts
shantamsultania Apr 16, 2021
2e0412a
Merge remote-tracking branch 'origin/master'
shantamsultania Apr 16, 2021
ff899a4
Requested Changes Made
Lakhankumawat Apr 17, 2021
cface0d
Merge pull request #899 from Ayushjain2205/udemy-scraper
avinashkranjan Apr 19, 2021
8ab0997
Merge pull request #897 from saidrishya/new_branch
avinashkranjan Apr 19, 2021
157980f
Merge pull request #895 from tanvi355/random_password
avinashkranjan Apr 19, 2021
b7de81c
Merge pull request #889 from shantamsultania/master
avinashkranjan Apr 19, 2021
1abec10
Merge pull request #880 from A-kriti/mini-google-assistant-1
avinashkranjan Apr 19, 2021
da0e6ed
Merge pull request #854 from Yuvraj-kadale/brick_game
avinashkranjan Apr 19, 2021
b7662b9
Merge pull request #851 from Lakhankumawat/TicTacToe-GUI
avinashkranjan Apr 19, 2021
dc12e6a
Merge pull request #891 from ShubhamGupta577/Fast-Algorithm
avinashkranjan Apr 19, 2021
3f0dd7a
Merge pull request #830 from anuragmukherjee2001/health_log_book
avinashkranjan Apr 19, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## Aws Script for AWS Management

This python script can be used to manage a AWS endorsement.

This provides features like :

### EC2 :

1. Create your own Key based SnapShots
2. Delete SnapShots
3. Delete/ Terminate any EC2 instance which does not have a user/ any specific tag
4. stop any useless Running Ec2 instance

### RDS :

1. delete RDS Instance
2. Delete RDS Cluster
3. Stop any useless Running RDS Cluster/Instance
4. Delete useless Snapshots
5. Delete any RDS Instance or Cluster which does not have a specific tag with it
6. Delete any RDS Snapshot that is older then 2 days

these Scripts can directly be used with AWS lambda function for Automation purposes as well

## Installation

First of all install [python]("https://www.python.org/downloads/") on your system.
```
pip install boto3
```

### Made with ❤️ by Shantam Sultania

You can find me at:-
[Linkedin](https://www.linkedin.com/in/shantam-sultania-737084175/) or [Github](https://github.com/shantamsultania) .

Happy coding ❤️ .
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def lambda_handler(event, context):
print("event " + str(event))
print("context " + str(context))
ec2_reg = boto3.client('ec2')
regions = ec2_reg.describe_regions()
for region in regions['Regions']:
region_name = region['RegionName']
instances = Ec2Instances(region_name)
deleted_counts = instances.delete_snapshots(1)
instances.delete_available_volumes()
print("deleted_counts for region " + str(region_name) + " is " + str(deleted_counts))
instances.shutdown()
print("For RDS")
rds = Rds(region_name)
rds.cleanup_snapshot()
rds.cleanup_instances()
return 'Hello from Lambda'
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from datetime import datetime, timedelta, timezone

import boto3


def get_delete_data(older_days):
delete_time = datetime.now(tz=timezone.utc) - timedelta(days=older_days)
return delete_time;


def is_ignore_shutdown(tags):
for tag in tags:
print("K " + str(tag['Key']) + " is " + str(tag['Value']))
if str(tag['Key']) == 'excludepower' and str(tag['Value']) == 'true':
print("Not stopping K " + str(tag['Key']) + " is " + str(tag['Value']))
return True
return False


def is_unassigned(tags):
if 'user' not in [t['Key'] for t in tags]:
return True
return False


class Ec2Instances(object):

def __init__(self, region):
print("region " + region)

# if you are not using AWS Tool Kit tool you will be needing to pass your access key and secret key here

# client = boto3.client('rds', region_name=region_name, aws_access_key_id=aws_access_key_id,
# aws_secret_access_key=aws_secret_access_key)
self.ec2 = boto3.client('ec2', region_name=region)

def delete_snapshots(self, older_days=2):
delete_snapshots_num = 0
snapshots = self.get_nimesa_created_snapshots()
for snapshot in snapshots['Snapshots']:
fmt_start_time = snapshot['StartTime']
if fmt_start_time < get_delete_data(older_days):
try:
self.delete_snapshot(snapshot['SnapshotId'])
delete_snapshots_num + 1
except Exception as e:
print(e)
return delete_snapshots_num

def get_user_created_snapshots(self):
snapshots = self.ec2.describe_snapshots(
Filters=[{
'Name': 'owner-id', 'Values': ['your owner id'],
}]) # Filters=[{'Name': 'description', 'Values': ['Created by Nimesa']}]
return snapshots

def delete_available_volumes(self):
volumes = self.ec2.describe_volumes()['Volumes']
for volume in volumes:
if volume['State'] == "available":
self.ec2.delete_volume(VolumeId=volume['VolumeId'])

def delete_snapshot(self, snapshot_id):
self.ec2.delete_snapshot(SnapshotId=snapshot_id)

def shutdown(self):
instances = self.ec2.describe_instances()
instance_to_stop = []
instance_to_terminate = []
for res in instances['Reservations']:
for instance in res['Instances']:
tags = instance.get('Tags')
if tags is None:
instance_to_terminate.append(instance['InstanceId'])
continue
if is_unassigned(tags):
print("instance_to_terminate " + instance['InstanceId'])
instance_to_terminate.append(instance['InstanceId'])
if is_ignore_shutdown(tags):
continue
if instance['State']['Code'] == 16:
instance_to_stop.append(instance['InstanceId'])

if any(instance_to_stop):
self.ec2.stop_instances(
InstanceIds=instance_to_stop
)
if any(instance_to_terminate):
print(instance_to_terminate)
self.ec2.terminate_instances(
InstanceIds=instance_to_terminate
)


if __name__ == "__main__":
ec2 = Ec2Instances('us-east-1')
ec2.delete_snapshots(3)
ec2.shutdown()
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import boto3
import datetime


class Rds(object):

def __init__(self, region) -> None:
super().__init__()
self.rds = boto3.client('rds', region)

def cleanup_snapshot(self):
self._cleanup_snapshot_instance()
self._cleanup_snapshots_clusters()

def cleanup_instances(self):
clusters = self.rds.describe_db_clusters()
for cluster in clusters['DBClusters']:
self._cleanup_cluster(cluster)
instances = self.rds.describe_db_instances()
for instance in instances['DBInstances']:
self._cleanup_instance(instance)

def _stop_cluster(self, identifier):
self.rds.stop_db_cluster(DBClusterIdentifier=identifier)

def _stop_instance(self, identifier):
self.rds.stop_db_instance(DBInstanceIdentifier=identifier)

def _delete_instance(self, identifier):
self.rds.describe_db_instances(DBInstanceIdentifier=identifier)

def _delete_cluster(self, identifier):
self.rds.describe_db_clusters(DBClusterIdentifier=identifier)

def _delete_instance_snapshot(self, identifier):
self.rds.delete_db_snapshot(DBSnapshotIdentifier=identifier)

def _delete_cluster_snapshot(self, identifier):
self.rds.delete_db_cluster_snapshot(DBClusterSnapshotIdentifier=identifier)

@staticmethod
def _can_delete_instance(tags):
if any('user' in tag for tag in tags):
return False

@staticmethod
def _can_stop_instance(tags):
for tag in tags:
if tag["Key"].lower() == 'excludepower' and tag['Value'].lower() == 'true':
return False
return True

@staticmethod
def _can_delete_snapshot(tags):
if tags is not None:
for tag in tags:
if tag['Key'].lower() == 'retain' and tag['Value'].lower() == 'true':
return False
return True

def _cleanup_instance(self, instance):
identifier = instance['DBInstanceIdentifier']
tags = instance['TagList']
if self._can_delete_instance(tags):
self._delete_instance(identifier)
else:
if self._can_stop_instance(tags) and instance['DBInstanceStatus'] == 'available':
try:
self._stop_instance(identifier)
except Exception as e:
print(str(e))

def _cleanup_cluster(self, cluster):
tags = cluster['TagList']
if self._can_delete_instance(tags):
self._delete_cluster(cluster['DBClusterIdentifier'])
else:
if self._can_stop_instance(tags) and cluster['Status'] == 'available':
try:
self._stop_cluster(cluster['DBClusterIdentifier'])
except Exception as e:
print(str(e))

def _cleanup_snapshots_clusters(self):
snapshots = self.rds.describe_db_cluster_snapshots()
for snapshot in snapshots['DBClusterSnapshots']:
tags = snapshot['TagList']
if self._can_delete_snapshot(tags) and self._is_older_snapshot(
str(snapshot['SnapshotCreateTime']).split(" ")):
try:
self._delete_cluster_snapshot(snapshot['DBClusterSnapshotIdentifier'])
except Exception as e:
print(str(e))

def _cleanup_snapshot_instance(self):
snapshots = self.rds.describe_db_snapshots()
for snapshot in snapshots['DBSnapshots']:
tags = snapshot['TagList']
if self._can_delete_snapshot(tags) and self._is_older_snapshot(
str(snapshot['SnapshotCreateTime']).split(" ")):
try:
self._delete_instance_snapshot(snapshot['DBSnapshotIdentifier'])
except Exception as e:
print(str(e))

@staticmethod
def _is_older_snapshot(snapshot_datetime):
snapshot_date = snapshot_datetime[0].split("-")
snapshot_date = datetime.date(int(snapshot_date[0]), int(snapshot_date[1]), int(snapshot_date[2]))
today = datetime.date.today()
if abs(today - snapshot_date).days > 2:
return True
else:
return False

@staticmethod
def _check_snapshot_tag(tags):
flag = False
for tag in tags:
if tag['Key'].lower() == 'retain' and tag['Value'].lower() == 'true':
flag = True
if flag:
return True
else:
return False


if __name__ == "__main__":
rds = Rds('us-east-1')
# # rds.shutdown()
rds.cleanup_snapshot()
rds.cleanup_instances()
29 changes: 29 additions & 0 deletions AWS Management Scripts/AWS testing Script/Readme.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Aws Script for testing using moto (a AWS testing framework )

This python script automatically generates a set of EC2 machine's with any demo ami Id that could be used in case of testing.

## Installation

First of all install [python]("https://www.python.org/downloads/") on your system.
```bash
pip install moto
pip install boto3
pip install Flask
```

## Results

![](https://i.postimg.cc/Jzx6f02c/image1.png)

![](https://i.postimg.cc/L6RVmRfy/image.png)

![](https://i.postimg.cc/Zq1r2h4x/image.png)

### Made with ❤️ by Shantam Sultania

You can find me at:-
[Linkedin](https://www.linkedin.com/in/shantam-sultania-737084175/) or [Github](https://github.com/shantamsultania) .

Happy coding ❤️ .


33 changes: 33 additions & 0 deletions AWS Management Scripts/AWS testing Script/agentMain.py
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from flask import Flask
from flask_ngrok import run_with_ngrok
import awstesting.awsTester as aws_testing

app = Flask(__name__)

# run_with_ngrok(app)


@app.route("/", methods=['POST', 'GET'])
def welcome():
message = "Welcome to create your own test Api for AWS for Ec2 just use your Url/ec2 and your 100 ec2 " \
"instance will be created in test environment if you dont want to use it in api based " \
"just go to code and use awsTesting class and done "
return message


# this api is to create an ec2 for testing

@app.route("/ec2", methods=['POST', 'GET'])
def ec2():
client = aws_testing.add_service("ec2", "us-east-1")
return aws_testing.test_create_ec2(client)


# you can add more apis of your choice here like
# create Volume, VPC and snapshots

# to do so just add a call function in awsTester class and agentMain and you are done

# run the app
if __name__ == '__main__':
app.run()
15 changes: 15 additions & 0 deletions AWS Management Scripts/AWS testing Script/awsHandler.py
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def create_ec2(client, ami_id, count):
client.run_instances(ImageId=ami_id, MinCount=count, MaxCount=count)


def create_ec2_snapshots(client, volume_id):
client.create_snapshot(VolumeId=volume_id)


def create_ec2_volume(client, AZ):
ab = client.create_volume(AZ)
return ab


def create_vpc(client, cidr_block):
client.create_vpc(CidrBlock=cidr_block)
Loading

AltStyle によって変換されたページ (->オリジナル) /