Created
November 3, 2016 23:22
-
-
Save bo67192/ed4617b19217a3f903dc0161524dcd91 to your computer and use it in GitHub Desktop.
Python example of using boto3 to filter instances and print their names
This file contains 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
import boto3 | |
# Create boto3 ec2 resource | |
ec2 = boto3.resource('ec2') | |
# Retrieve instances with a name tag that contains Webserver | |
filters = [{'Name':'tag:instanceSchedule', 'Values': ['*Webserver*']}] | |
instances = ec2.instances.filter(Filters=filters) | |
# For each insteance with a tag | |
for i in instances: | |
for tag in i.tags: | |
if tag['Key'] == 'Name': | |
instanceName = tag['Value'] | |
print(instanceName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment