Created
December 18, 2015 22:32
-
-
Save babo/7ada4b129aa38c0a43bf to your computer and use it in GitHub Desktop.
List security groups, EC2, RDS and Elasticache instances and they security groups.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import boto3 | |
def main(): | |
region_names = [x['RegionName'] for x in boto3.client('ec2').describe_regions()['Regions']] | |
for region_name in region_names: | |
ec2 = boto3.resource('ec2', region_name=region_name) | |
for sg in ec2.security_groups.iterator(): | |
print(region_name, 'security_group', sg.group_name, sg.group_id) | |
for instance in ec2.instances.iterator(): | |
print(region_name, 'instance', instance.instance_id, instance.launch_time.isoformat(), instance.state['Name'], ' '.join([x['GroupId'] for x in instance.security_groups]), [tuple(x.values()) for x in instance.tags or []]) | |
for elb in boto3.client('elb', region_name=region_name).describe_load_balancers()['LoadBalancerDescriptions']: | |
print(region_name, 'elb', elb.get('LoadBalancerName', '""'), elb.get('VPCId', '""'), ' '.join(elb.get('SecurityGroups', ['""']))) | |
for rds in boto3.client('rds', region_name=region_name).describe_db_clusters()['DBClusters']: | |
print(region_name, 'rds', rds['DBClusterIdentifier'], rds['Status'], ' '.join([x['VpcSecurityGroupId'] for x in rds['VpcSecurityGroups']])) | |
for cache in boto3.client('elasticache', region_name=region_name).describe_cache_clusters()['CacheClusters']: | |
print(region_name, 'elasticache', cache['CacheClusterId'], cache['Engine'], cache['CacheNodeType'], ' '.join([x['SecurityGroupId'] for x in cache['SecurityGroups']])) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment