feat: porting scripts to python
This commit is contained in:
Generated
+5
@@ -0,0 +1,5 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
Generated
+10
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.14 (xpk-git)" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredErrors">
|
||||||
|
<list>
|
||||||
|
<option value="N802" />
|
||||||
|
<option value="N806" />
|
||||||
|
<option value="N803" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.13 (aws-inventory)" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.14 (xpk-git)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
Generated
+8
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/aws-inventory.iml" filepath="$PROJECT_DIR$/.idea/aws-inventory.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -6,6 +6,7 @@ Scripts to collect AWS resource inventory in all regions.
|
|||||||
- awscli
|
- awscli
|
||||||
- gnu parallel
|
- gnu parallel
|
||||||
- miller
|
- miller
|
||||||
|
- python 3.13+
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
Run run-inventory-scripts.sh which will invoke a collection of scripts. TSV is returned for visibility.
|
Run run-inventory-scripts.sh which will invoke a collection of scripts. TSV is returned for visibility.
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
#RESTYPE=ApiGateway
|
|
||||||
|
|
||||||
# Generate inventory in all regions
|
|
||||||
echo "RestAPI,Scope"
|
|
||||||
aws apigateway get-rest-apis | jq -cr '.items[] | [.name, .endpointConfiguration.types[0]] | @csv'
|
|
||||||
Executable
+23
@@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
r"""
|
||||||
|
Documentation
|
||||||
|
|
||||||
|
License: This program is released under the MIT License
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Imports
|
||||||
|
import boto3
|
||||||
|
|
||||||
|
|
||||||
|
# Main function
|
||||||
|
def main() -> None:
|
||||||
|
client = boto3.client('apigateway')
|
||||||
|
response = client.get_rest_apis()
|
||||||
|
|
||||||
|
print("RestAPIName,Scope")
|
||||||
|
for i in response['items']:
|
||||||
|
print(f'{i["name"]}, {i["endpointConfiguration"]["types"][0]}')
|
||||||
|
|
||||||
|
# Call main function
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Generate inventory in all regions
|
|
||||||
|
|
||||||
echo "CFDist,Alias"
|
|
||||||
aws cloudfront list-distributions | jq -cr '.DistributionList.Items[] | [.Id, .Aliases.Items[0]] | @csv'
|
|
||||||
|
|
||||||
Executable
+23
@@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
r"""
|
||||||
|
Documentation
|
||||||
|
|
||||||
|
License: This program is released under the MIT License
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Imports
|
||||||
|
import boto3
|
||||||
|
|
||||||
|
|
||||||
|
# Main function
|
||||||
|
def main() -> None:
|
||||||
|
client = boto3.client('cloudfront')
|
||||||
|
response = client.list_distributions()
|
||||||
|
|
||||||
|
print("Distribution, Alias, OriginId")
|
||||||
|
for i in response['DistributionList']['Items']:
|
||||||
|
print(f'{i["Id"]}, {i["Aliases"]["Items"][0]}, {i["Origins"]["Items"][0]["Id"]}')
|
||||||
|
|
||||||
|
# Call main function
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
function listRes() {
|
|
||||||
aws --region $1 logs describe-log-groups | jq -cr '.logGroups[] | [.logGroupName, .retentionInDays, .logGroupClass] | @csv' | tr -d \"
|
|
||||||
}
|
|
||||||
|
|
||||||
export -f listRes
|
|
||||||
|
|
||||||
# Generate inventory in all regions
|
|
||||||
|
|
||||||
echo "LogGroup, Retention, Class"
|
|
||||||
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
+30
@@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
r"""
|
||||||
|
Documentation
|
||||||
|
|
||||||
|
License: This program is released under the MIT License
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Imports
|
||||||
|
import boto3
|
||||||
|
|
||||||
|
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('logs', region_name=region_name)
|
||||||
|
response = client.describe_log_groups()
|
||||||
|
for logGroup in response['logGroups']:
|
||||||
|
print(f"{logGroup['logGroupName']}, {logGroup.get('retentionInDays')}, {logGroup['storedBytes']}, {region_name}")
|
||||||
|
|
||||||
|
# Main function
|
||||||
|
def main() -> None:
|
||||||
|
print("logGroupName,retentionInDays,storedBytes,region")
|
||||||
|
for r in getRegions():
|
||||||
|
printResources(r)
|
||||||
|
|
||||||
|
# Call main function
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Generate inventory in all regions
|
|
||||||
echo "BucketName"
|
|
||||||
aws s3api list-buckets --query Buckets[].Name --output text | sed 's/\t/\n/g'
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
r"""
|
||||||
|
Documentation
|
||||||
|
|
||||||
|
License: This program is released under the MIT License
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Imports
|
||||||
|
import boto3
|
||||||
|
|
||||||
|
|
||||||
|
# Main function
|
||||||
|
def main() -> None:
|
||||||
|
s3_client = boto3.client('s3')
|
||||||
|
|
||||||
|
# Get the list of all buckets
|
||||||
|
response = s3_client.list_buckets()
|
||||||
|
|
||||||
|
# Print the names of the buckets
|
||||||
|
print('Buckets')
|
||||||
|
for bucket in response['Buckets']:
|
||||||
|
print(f'{bucket["Name"]}')
|
||||||
|
|
||||||
|
# Call main function
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
for i in aws*.sh; do
|
for i in aws*.{py,sh}; do
|
||||||
echo "# $i"
|
echo "# $i"
|
||||||
bash $i | mlr --c2t cat | column -t
|
./"$i" | mlr --c2t cat | column -t
|
||||||
wait $!
|
wait $!
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user