Last active
September 29, 2016 08:39
-
-
Save esc/88780a70f9acb6a53f603ebbe5fcc8ec to your computer and use it in GitHub Desktop.
Expose a bug in moto EC2 tag filtering
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 | |
import moto | |
@moto.mock_ec2 | |
def expose(): | |
ec2 = boto3.resource('ec2') | |
blue, green = ec2.create_instances( | |
ImageId='ANY_ID', MinCount=2, MaxCount=2) | |
ec2.create_tags(Resources=[blue.instance_id], | |
Tags=[{"Key": "environment", "Value": "blue"}, | |
{"Key": "application", "Value": "api"}, | |
]) | |
ec2.create_tags(Resources=[green.instance_id], | |
Tags=[{"Key": "environment", "Value": "green"}, | |
{"Key": "application", "Value": "api"}, | |
]) | |
filter_ = [{'Name': 'tag-key', 'Values': ['application']}, | |
{'Name': 'tag-value', 'Values': ['api']}, | |
{'Name': 'tag-key', 'Values': ['environment']}, | |
{'Name': 'tag-value', 'Values': ['green']}, | |
] | |
instances = list(ec2.instances.filter(Filters=filter_)) | |
print(instances) | |
expose() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment