forked from duo-labs/cloudmapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect_data.sh
executable file
·68 lines (52 loc) · 2.56 KB
/
collect_data.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
set -euo pipefail
echo "* Startup checks"
if [ $# -ne 2 ] || [ "$1" != "--account" ] ; then
echo "ERROR: No account name specified"
echo "Usage:"
echo " $0 --account my_account"
exit -1
fi
# Ensure the aws cli exists
aws --version > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR: Install the aws cli"
exit -1
fi
# Ensure we have AWS credentials
aws sts get-caller-identity > /dev/null
if [ $? -ne 0 ]; then
echo "ERROR: No AWS credentials set"
exit -1
fi
# Ensure jq exists
jq --help > /dev/null
if [ $? -ne 0 ]; then
echo "ERROR: jq not found"
exit -1
fi
account=$2
mkdir -p "$account"
cd $account
echo "* Getting region names"
aws ec2 describe-regions > describe-regions.json
# Create directory for each region name
cat describe-regions.json | jq -r '.Regions[].RegionName' | xargs -I{} sh -c 'mkdir -p $1' -- {}
echo "* Getting VPC info"
cat describe-regions.json | jq -r '.Regions[].RegionName' | xargs -I{} sh -c 'aws ec2 --region "$1" describe-vpcs > "$1/describe-vpcs.json"' -- {}
echo "* Getting AZ info"
cat describe-regions.json | jq -r '.Regions[].RegionName' | xargs -I{} sh -c 'aws ec2 --region "$1" describe-availability-zones > "$1/describe-availability-zones.json"' -- {}
echo "* Getting subnet info"
cat describe-regions.json | jq -r '.Regions[].RegionName' | xargs -I{} sh -c 'aws ec2 --region "$1" describe-subnets > "$1/describe-subnets.json"' -- {}
echo "* Getting EC2 info"
cat describe-regions.json | jq -r '.Regions[].RegionName' | xargs -I{} sh -c 'aws ec2 --region "$1" describe-instances > "$1/describe-instances.json"' -- {}
echo "* Getting RDS info"
cat describe-regions.json | jq -r '.Regions[].RegionName' | xargs -I{} sh -c 'aws rds --region "$1" describe-db-instances > "$1/describe-db-instances.json"' -- {}
echo "* Getting ELB info"
cat describe-regions.json | jq -r '.Regions[].RegionName' | xargs -I{} sh -c 'aws elb --region "$1" describe-load-balancers > "$1/describe-load-balancers.json"' -- {}
echo "* Getting security group info"
cat describe-regions.json | jq -r '.Regions[].RegionName' | xargs -I{} sh -c 'aws ec2 --region "$1" describe-security-groups > "$1/describe-security-groups.json"' -- {}
echo "* Getting network interface info"
cat describe-regions.json | jq -r '.Regions[].RegionName' | xargs -I{} sh -c 'aws ec2 --region "$1" describe-network-interfaces > "$1/describe-network-interfaces.json"' -- {}
echo "* Getting VPC peering info"
cat describe-regions.json | jq -r '.Regions[].RegionName' | xargs -I{} sh -c 'aws ec2 --region "$1" describe-vpc-peering-connections > "$1/describe-vpc-peering-connections.json"' -- {}