Posts

Showing posts with the label SRE
Image
AWS Infrastructure Inventory Discovery Blog Streamline Your AWS Inventory with Automated Discovery and Reporting Managing resources across multiple AWS accounts and regions can be a daunting task, especially as your cloud infrastructure grows. To simplify this process, I have developed an AWS Inventory Discovery tool that scans all your AWS accounts across all regions and compiles a comprehensive, searchable HTML report. In this blog, I'll walk you through the features, benefits, and the technical details of this solution. Introduction As organizations scale their use of AWS, keeping track of resources scattered across various accounts and regions becomes increasingly challenging. Manual inventory management is not only time-consuming but also prone to errors. This is where the AWS Inventory Discovery tool comes in. Features Comprehensive Scanning : The tool scans all your AWS accounts across all regions, ensu...

AMI Age Calculator of Running AWS EC2 Instances and Generate CSV Report

#!/bin/bash # Initialize variables with default values ACCOUNTID="<Your AccountID>" REGION="<Your Region>" OUTPUT_CSV="$ACCOUNTID-$REGION-ami_age_report.csv" # Define the CSV file name rm -rf $OUTPUT_CSV # Parse command line options while getopts "a:b:" option; do case $option in a) ACCOUNTID=${OPTARG} ;; b) REGION=${OPTARG} ;; *) echo "usage: $0 [-a ACCOUNTID] [-b REGION]" >&2 exit 1 ;; esac done # List instances and AMI IDs in the specified region instances_json=$(aws ec2 describe-instances --region "$REGION" --query 'Reservations[*].Instances[*].[InstanceId,ImageId]' --output json) # For local # Get the current timestamp current_time=$(date -u +%s) # Initialize the CSV file with headers echo "AccountID,Region,InstanceID,AMIID,AMIAge (months)" > "$OUTPUT_CSV" # Iterate through instances and append to the CSV file for row in $(echo "$insta...

AWS S3 Bucket Sizer || Bash Script

  #! /bin/sh set -e # Script finds all buckets within the specified account and outputs the total size together with the number of files contained in the bucket. usage () { echo " Usage: $0 <aws config profile> " echo " e.g.: $0 aws_production " echo " Make sure your AWS CLI is configured " echo " " exit 1 } if [ -z " $1 " ] ; then usage fi AWS_PROFILE= $1 # find all buckets in the account. S3_BUCKET_IDS= $( aws s3api list-buckets --profile $AWS_PROFILE --query ' Buckets[*].Name ' --output text ) for i in ${S3_BUCKET_IDS[@]} do echo " calculating size of bucket: " $i aws s3api --profile $AWS_PROFILE list-objects --bucket $i --output json --query " [sum(Contents[].Size), length(Contents[])] " | awk ' NR!=2 {print $0;next} NR==2 {print $0/1024/1024/1024" GB"} ' done

AWS (Listing Unattached security groups in AWS Cloud) || Bash Script

  Hi, guys when you are working on the AWS cloud platform you will come across to get the info about unattached security groups in order to do garbage cleaning, It's a tricky job to do here I am giving AWS CLI commands to get the unattached security groups. Note: this only considers security use in EC2, not other services like RDS. You’ll need to do more work to include security groups used outside EC2. The good thing is you can’t easily (might not even be possible) to delete active security groups if you miss one associated w/another service.Using the newer AWS CLI tool, I found an easy way to get what I need: 1st Step — First, get a list of all security groups aws ec2 describe-security-groups — query ‘SecurityGroups[*].GroupId’ — output text |tr ‘\t’’\n’ Then get all security groups tied to an instance, then piped to sort then uniq: aws ec2 describe-instances query‘Reservations[*].Instances[*].SecurityGroups[*].GroupId’ — output text |tr ‘\t’’\n’|sort |uniq Then put it together a...

AWS CLI Get Security Group ID with Name. Python Boto3 [ wild card support] Python Boto3

 """ Author Praveen This Simple Boto Script will list the AWS  security group with name provide [ Wildcard supported] """ import boto3 AWS_REGION = "us-west-2" fullauth = boto3.session.Session(profile_name='<YourProfile>') ec2 = fullauth.client('ec2' , region_name=AWS_REGION) group_name = '*<YourSearchString>' response = ec2.describe_security_groups(     Filters=[         dict(Name='group-name', Values=[group_name])     ] ) for securityGroup in response['SecurityGroups']:    print("SG ID: {}, Name: {}".format(securityGroup['GroupId'], securityGroup['GroupName'])) #This will list Security Group Name along with Security Group ID     print("SG ID: {}".format(securityGroup['GroupId'])) # This will List Only Security Group IDS

AWS CLI Get Security Group ID with Name.[ wild card support] Bash Script

  Hi guys, If you are wondering How can I get the ID of an AWS security group if I know the name? Here is the solution. Get the Security ID with the wild card Name. #!/bin/bash #Author Praveen SearchString=<*YourSearchString*> # Note : wild cards supported for VPCS in `aws ec2 --output text --query 'Vpcs[*].{VpcId:VpcId}' describe-vpcs` ; do aws ec2 describe-security-groups --filter Name=vpc-id,Values=$VPCS Name=group-name,Values=$searchstring --query 'SecurityGroups[*].[GroupId]' --output text done 2. With the above solution we can automate the other tasks. eg: add tags to security groups. for VPCS in `aws ec2 --output text --query 'Vpcs[*].{VpcId:VpcId}' describe-vpcs` ; do echo " Tagging Search String Created Security Groups" aws ec2 describe-security-groups --filter Name=vpc-id,Values=$VPCS Name=group- name,Values=$searchstring --query 'SecurityGroups[*].[GroupId]' --output text | xargs - I {} aws ...