Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #!/usr/local/bin/python
  2.  
  3. import boto3
  4. import sys, re
  5.  
  6. region = 'ap-southeast-2'
  7.  
  8. s3 = boto3.resource('s3')
  9. client = boto3.client('cloudformation', region_name=region)
  10. cfn = boto3.resource('cloudformation', region_name=region)
  11. match_hybris = re.compile('HYBRIS')
  12. ec2 = boto3.client('ec2', region_name=region)
  13.  
  14. for stack in cfn.stacks.all():
  15. if match_hybris.match(stack.stack_name):
  16. stack_resources = client.describe_stack_resources(
  17. StackName=stack.stack_name
  18. )
  19. print("Stack: " + stack.stack_name)
  20. for resource in stack_resources['StackResources']:
  21. if resource['ResourceType'] == 'AWS::EC2::Instance': #in ( 'AWS::EC2::Instance', 'AWS::Route53::RecordSet'):
  22. instance = ec2.describe_instances(
  23. InstanceIds=[resource['PhysicalResourceId']]
  24. )
  25. print("\tInstance: " + resource['LogicalResourceId'] + " instance-id: " + resource['PhysicalResourceId']
  26. + " IP: " + instance['Reservations'][0]['Instances'][0]['PrivateIpAddress'])
  27. if resource['ResourceType'] == 'AWS::Route53::RecordSet':
  28. print("\tDNS: " + resource['LogicalResourceId'] + " record: " + resource['PhysicalResourceId'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement