Skip to content

Olisaemeka111/python-automation-scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Python AWS Automation Scripts

AWS Python Automation Python Boto3 License

A comprehensive collection of Python scripts for automating AWS infrastructure management, monitoring, optimization, and security compliance. These scripts leverage the AWS SDK for Python (boto3) to streamline DevOps operations, enhance security, and reduce operational costs.

πŸ“‹ Table of Contents

πŸ” Overview

This repository contains over 40 Python scripts designed to automate common AWS administrative tasks, security checks, and cost optimization processes. These scripts are based on real-world DevOps use cases and best practices for AWS cloud management.

✨ Features

  • Automation: Reduce manual effort for routine AWS management tasks
  • Cost Optimization: Identify and eliminate unnecessary AWS resource costs
  • Security Compliance: Automate security audits and enforce best practices
  • Infrastructure Management: Simplify resource provisioning and configuration
  • Monitoring: Track performance metrics and health status of AWS resources
  • Disaster Recovery: Automate backup and recovery procedures

πŸ“ Repository Structure

The repository is organized by AWS service and automation purpose:

python-automation-scripts/
β”œβ”€β”€ README.md
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ EC2 & Compute/
β”‚   β”œβ”€β”€ manage_ec2_instance.py
β”‚   β”œβ”€β”€ ec2_instance_scheduler.py
β”‚   β”œβ”€β”€ ec2_custom_ami_builder.py
β”‚   └── ...
β”œβ”€β”€ Storage/
β”‚   β”œβ”€β”€ delete_old_s3_objects.py
β”‚   β”œβ”€β”€ sync_s3_buckets.py
β”‚   └── ...
β”œβ”€β”€ Security/
β”‚   β”œβ”€β”€ security_compliance_checker.py
β”‚   β”œβ”€β”€ rotate_iam_keys.py
β”‚   └── ...
└── ...

πŸš€ Getting Started

Prerequisites

  • Python 3.6 or higher
  • AWS account with appropriate permissions
  • AWS CLI installed and configured
  • Boto3 library

Installation

  1. Clone this repository:

    git clone https://github.com/Olisaemeka111/python-automation-scripts.git
    cd python-automation-scripts
  2. Install the required dependencies:

    pip install -r requirements.txt
  3. Configure AWS credentials if you haven't already:

    aws configure

    Provide your AWS Access Key ID, Secret Access Key, default region (e.g., us-east-1), and output format (e.g., json).

Configuration

Most scripts use the default AWS credentials and region configuration from your environment. Some scripts may require additional configuration parameters, which are typically specified as command-line arguments or in configuration files.

πŸ“š Script Categories

EC2 & Compute Management

Script Description Usage
manage_ec2_instance.py Start, stop, restart, or terminate EC2 instances python manage_ec2_instance.py <instance_id> <action>
ec2_instance_scheduler.py Schedule EC2 instances to start/stop based on time patterns python ec2_instance_scheduler.py
ec2_custom_ami_builder.py Create and manage custom AMIs with specific configurations python ec2_custom_ami_builder.py <instance_id> <ami_name>
auto_scale_ec2.py Configure auto-scaling groups with CloudWatch alarms python auto_scale_ec2.py
create_ami.py Create Amazon Machine Images from EC2 instances python create_ami.py <instance_id> <ami_name>
restart_unhealthy_instances.py Detect and restart unhealthy EC2 instances python restart_unhealthy_instances.py
stop_idle_instances.py Identify and stop underutilized EC2 instances python stop_idle_instances.py <cpu_threshold> <hours>
delete_unused_ebs_volumes.py Find and delete unattached EBS volumes python delete_unused_ebs_volumes.py
tag_ec2_instance.py Add or update tags on EC2 resources python tag_ec2_instance.py <instance_id> <key> <value>

Storage & Database Management

Script Description Usage
delete_old_s3_objects.py Implement S3 data retention policies python delete_old_s3_objects.py <bucket> <days>
sync_s3_buckets.py Copy objects between S3 buckets python sync_s3_buckets.py <source> <destination>
enable_s3_bucket_versioning.py Enable versioning on S3 buckets python enable_s3_bucket_versioning.py
backup_rds_to_s3.py Export RDS snapshots to S3 for backup python backup_rds_to_s3.py <db_instance> <bucket>
create_rds_snapshot.py Create RDS database snapshots python create_rds_snapshot.py <db_instance>
export_dynamodb_to_s3.py Export DynamoDB tables to S3 python export_dynamodb_to_s3.py <table> <bucket>
dynamodb_autoscaling_manager.py Configure DynamoDB auto-scaling python dynamodb_autoscaling_manager.py <table>
cleanup_snapshots.py Delete outdated EC2 snapshots python cleanup_snapshots.py <days>

Security & Compliance

Script Description Usage
security_compliance_checker.py Comprehensive AWS security audit python security_compliance_checker.py
rotate_iam_keys.py Rotate IAM access keys python rotate_iam_keys.py <username> <days>
check_open_security_groups.py Identify security groups with open access python check_open_security_groups.py
list_iam_users_and_policies.py List IAM users and their policies python list_iam_users_and_policies.py
aws_account_scanner.py Scan AWS account for security issues python aws_account_scanner.py
aws_resource_filter.py Filter AWS resources by various criteria python aws_resource_filter.py <resource_type>

Networking & CDN

Script Description Usage
vpc_analyzer.py Analyze VPC configurations and security python vpc_analyzer.py <vpc_id>
update_dns_record.py Update Route53 DNS records python update_dns_record.py <domain> <ip> <zone_id>
cloudfront_cache_invalidator.py Manage CloudFront cache invalidations python cloudfront_cache_invalidator.py <dist_id> <paths>
route53_dns_backup.py Backup Route53 DNS configurations python route53_dns_backup.py
vpc_peering_manager.py Manage VPC peering connections python vpc_peering_manager.py

Serverless & Container Management

Script Description Usage
deploy_lambda_function.py Deploy Lambda functions python deploy_lambda_function.py <function> <zip_file>
cleanup_old_lambda_versions.py Remove old Lambda versions python cleanup_old_lambda_versions.py <function>
monitor_lambda_metrics.py Track Lambda performance metrics python monitor_lambda_metrics.py <function>
lambda_layer_manager.py Manage Lambda layers python lambda_layer_manager.py
cleanup_ecr_repositories.py Clean up old ECR images python cleanup_ecr_repositories.py <repo> <count>
ecs_service_deployer.py Deploy services to ECS clusters python ecs_service_deployer.py <cluster> <service>
eks_management.py Manage EKS Kubernetes clusters python eks_management.py <cluster>

Cost Optimization

Script Description Usage
find_cost_savings.py Identify cost optimization opportunities python find_cost_savings.py
get_aws_billing.py Monitor AWS billing costs python get_aws_billing.py
aws_resource_analyzer.py Analyze resource usage patterns python aws_resource_analyzer.py
aws_infrastructure_cleanup.py Clean up unused AWS resources python aws_infrastructure_cleanup.py
aws_targeted_cleanup.py Target specific resources for cleanup python aws_targeted_cleanup.py <resource_type>

Monitoring & Reporting

Script Description Usage
automated_health_check.py Monitor AWS resource health python automated_health_check.py
create_cloudwatch_alarm.py Set up CloudWatch alarms python create_cloudwatch_alarm.py <resource> <metric>
aws_resource_lister.py List all resources in an AWS account python aws_resource_lister.py
aws_resource_summarizer.py Generate summary reports of AWS resources python aws_resource_summarizer.py
aws_detailed_resource_list.py Create detailed resource inventories python aws_detailed_resource_list.py
test_boto3_setup.py Verify Boto3 configuration python test_boto3_setup.py
json_to_txt_converter.py Convert JSON outputs to readable text python json_to_txt_converter.py <input> <output>

πŸ“ Usage Examples

Example 1: Scanning AWS Account for Security Issues

python aws_account_scanner.py

This script performs a comprehensive security scan of your AWS account, checking for:

  • Public S3 buckets
  • Unencrypted EBS volumes
  • Security groups with open ports
  • IAM users without MFA
  • Expired IAM access keys
  • CloudTrail logging status
  • And more...

The results are saved to a JSON file with a timestamp.

Example 2: Scheduling EC2 Instances

python ec2_instance_scheduler.py --config scheduler_config.json

This script allows you to define start/stop schedules for EC2 instances based on tags, time patterns, and utilization metrics. It can help reduce costs by automatically shutting down non-production instances during off-hours.

Example 3: Comprehensive Cost Optimization

python find_cost_savings.py --detailed-report

This script analyzes your AWS environment to identify cost-saving opportunities, including:

  • Underutilized EC2 instances
  • Unused Elastic IPs
  • Old EBS snapshots
  • Idle load balancers
  • Oversized RDS instances
  • Unattached EBS volumes

πŸ›‘οΈ Security Considerations

These scripts interact with your AWS account and can make changes to your resources. Always:

  1. Review the code before running it
  2. Ensure you have appropriate permissions
  3. Test in a non-production environment first
  4. Be careful with scripts that delete or modify resources
  5. Never hardcode AWS credentials in scripts
  6. Use IAM roles and policies to limit script permissions

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Based on real-world DevOps use cases and AWS best practices
  • Inspired by the article "20 Must-Have Python Boto3 Scripts for AWS Automation" by Antoine Fongang
  • Thanks to the AWS and Python communities for their valuable resources and documentation

About

Scripts to automate DevOps processes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages