feat: porting shell scripts to python
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
function listRes() {
|
||||
aws --region $1 lambda list-functions | jq -cr '.Functions[] | [.FunctionName, .Runtime, .Architectures[]] | @csv' | tr -d \"
|
||||
}
|
||||
|
||||
export -f listRes
|
||||
|
||||
# Generate inventory in all regions
|
||||
|
||||
echo "FunctionName, Runtime, Architecture"
|
||||
aws --region=us-east-1 ec2 describe-regions --query Regions[].RegionName --output text | sed -e 's/\t/\n/g' | while read r; do
|
||||
sem -j6 listRes $r
|
||||
done
|
||||
|
||||
sem --wait
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
r"""
|
||||
Documentation
|
||||
|
||||
License: This program is released under the MIT License
|
||||
"""
|
||||
|
||||
# Imports
|
||||
import boto3
|
||||
import concurrent.futures
|
||||
|
||||
|
||||
def getRegions(all_regions=False):
|
||||
ec2 = boto3.client('ec2')
|
||||
response = ec2.describe_regions(AllRegions=all_regions)
|
||||
return [region['RegionName'] for region in response['Regions']]
|
||||
|
||||
def printResources(region_name: str):
|
||||
client = boto3.client('lambda', region_name=region_name)
|
||||
response = client.list_functions()
|
||||
for i in response['Functions']:
|
||||
print(f"{i['FunctionName']}, {i['Runtime']}, {i['Architectures'][0]}, {region_name}")
|
||||
|
||||
# Main function
|
||||
def main() -> None:
|
||||
print("FunctionName,Runtime,Architectures,region")
|
||||
with concurrent.futures.ProcessPoolExecutor(max_workers=6) as executor:
|
||||
futures = [executor.submit(printResources, region_name=r) for r in getRegions()]
|
||||
results = [future.result() for future in concurrent.futures.wait(futures).done]
|
||||
|
||||
# Call main function
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
+5
-2
@@ -7,6 +7,8 @@ License: This program is released under the MIT License
|
||||
|
||||
# Imports
|
||||
import boto3
|
||||
import concurrent.futures
|
||||
|
||||
|
||||
def getRegions(all_regions=False):
|
||||
ec2 = boto3.client('ec2')
|
||||
@@ -22,8 +24,9 @@ def printResources(region_name: str):
|
||||
# Main function
|
||||
def main() -> None:
|
||||
print("logGroupName,retentionInDays,storedBytes,region")
|
||||
for r in getRegions():
|
||||
printResources(r)
|
||||
with concurrent.futures.ProcessPoolExecutor(max_workers=6) as executor:
|
||||
futures = [executor.submit(printResources, region_name=r) for r in getRegions()]
|
||||
results = [future.result() for future in concurrent.futures.wait(futures).done]
|
||||
|
||||
# Call main function
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
function listRes() {
|
||||
aws --region $1 opensearch list-domain-names | jq -cr '.DomainNames[] | [.DomainName, .EngineType] | @csv' | sed "s/$/,$1/"
|
||||
}
|
||||
|
||||
export -f listRes
|
||||
|
||||
# Generate inventory of ec2 in all regions
|
||||
|
||||
echo "DomainName, EngineType, Region"
|
||||
aws --region=us-east-1 ec2 describe-regions --query Regions[].RegionName --output text | sed -e 's/\t/\n/g' | while read r; do
|
||||
sem -j6 listRes $r
|
||||
done
|
||||
|
||||
sem --wait
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python3
|
||||
r"""
|
||||
Documentation
|
||||
|
||||
License: This program is released under the MIT License
|
||||
"""
|
||||
|
||||
# Imports
|
||||
import boto3
|
||||
import concurrent.futures
|
||||
|
||||
def getRegions(all_regions=False):
|
||||
ec2 = boto3.client('ec2')
|
||||
response = ec2.describe_regions(AllRegions=all_regions)
|
||||
return [region['RegionName'] for region in response['Regions']]
|
||||
|
||||
def printResources(region_name: str):
|
||||
client = boto3.client('opensearch', region_name=region_name)
|
||||
response = client.list_domain_names()
|
||||
for i in response['DomainNames']:
|
||||
print(f"{i['DomainName']}, {i['EngineType']}, {region_name}")
|
||||
|
||||
# Main function
|
||||
def main() -> None:
|
||||
print("DomainName,EngineType,region")
|
||||
with concurrent.futures.ProcessPoolExecutor(max_workers=6) as executor:
|
||||
futures = [executor.submit(printResources, region_name=r) for r in getRegions()]
|
||||
results = [future.result() for future in concurrent.futures.wait(futures).done]
|
||||
|
||||
# Call main function
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
function listRes() {
|
||||
aws rds describe-db-instances --region $1 | jq -cr '.DBInstances[] | [.DBInstanceIdentifier, .DBInstanceClass, .Engine, .AvailabilityZone, .MultiAZ] | @csv' | tr -d \"
|
||||
}
|
||||
|
||||
export -f listRes
|
||||
|
||||
# Generate inventory of ec2 in all regions
|
||||
|
||||
echo "InstanceId,InstanceClass,Engine,AZ,MultiAz"
|
||||
aws --region=us-east-1 ec2 describe-regions --query Regions[].RegionName --output text | sed -e 's/\t/\n/g' | while read r; do
|
||||
sem -j6 listRes $r
|
||||
done
|
||||
|
||||
sem --wait
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python3
|
||||
r"""
|
||||
Documentation
|
||||
|
||||
License: This program is released under the MIT License
|
||||
"""
|
||||
|
||||
# Imports
|
||||
import boto3
|
||||
import concurrent.futures
|
||||
|
||||
def getRegions(all_regions=False):
|
||||
ec2 = boto3.client('ec2')
|
||||
response = ec2.describe_regions(AllRegions=all_regions)
|
||||
return [region['RegionName'] for region in response['Regions']]
|
||||
|
||||
def printResources(region_name: str):
|
||||
client = boto3.client('rds', region_name=region_name)
|
||||
response = client.describe_db_instances()
|
||||
for i in response['DBInstances']:
|
||||
print(f"{i['DBInstanceIdentifier']}, {i['DBInstanceClass']}, {i['Engine']}, {i['EngineVersion']}, {i['MultiAZ']}, {region_name}")
|
||||
|
||||
# Main function
|
||||
def main() -> None:
|
||||
print("DBInstanceIdentifier, DBInstanceClass, Engine, EngineVersion, MultiAZ, Region")
|
||||
with concurrent.futures.ProcessPoolExecutor(max_workers=6) as executor:
|
||||
futures = [executor.submit(printResources, region_name=r) for r in getRegions()]
|
||||
results = [future.result() for future in concurrent.futures.wait(futures).done]
|
||||
|
||||
# Call main function
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user