Skip to content Skip to sidebar Skip to footer

If I Just Wanted To Get Ec2 Instances Whose Value Of Tag's Env Is "dev" , How Should I Modify Code Based On This Script?

[This script let me get all instances] How Can I use Python dictionary Grouping AWS instances by tag's name? When I run the script in this link : #!/usr/bin/env python # -*- encodi

Solution 1:

You want to consider the tags which end with -dev.

Change this line:

if'Name'in instance.tags:

to:

if'Name'in instance.tags and instance.tags['Name'].endswith('-dev'):

You can also make this as a method and pass your "environment" like dev, prod, stage instead of modifying code each time.

Post a Comment for "If I Just Wanted To Get Ec2 Instances Whose Value Of Tag's Env Is "dev" , How Should I Modify Code Based On This Script?"