Created
February 25, 2020 15:54
-
-
Save gmariette/54918713a3ccc7acdd6075e6b0f6f0c9 to your computer and use it in GitHub Desktop.
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
| ec2Client = boto3.Session( | |
| region_name=awsAccounts[awsAccount]["region"], | |
| aws_access_key_id=ACCESS_KEY, | |
| aws_secret_access_key=SECRET_KEY, | |
| aws_session_token=SESSION_TOKEN | |
| ).client('ec2') | |
| for env in awsAccounts[awsAccount]['envs']: | |
| instancesByEnv[env] = {} | |
| filters = [{'Name':'tag:Name', 'Values':[env+'*']}] | |
| instances = ec2Client.describe_instances( | |
| Filters=filters | |
| ) | |
| for reservation in instances['Reservations']: | |
| for instance in reservation['Instances']: | |
| if instance['State']['Name'] != 'terminated': | |
| ip = instance['PrivateIpAddress'] | |
| for tag in instance['Tags']: | |
| if tag['Key'] == "Name": | |
| instancesByEnv[env][tag['Value']] = ip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment