Skip to content

Instantly share code, notes, and snippets.

@esc
Last active September 29, 2016 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esc/88780a70f9acb6a53f603ebbe5fcc8ec to your computer and use it in GitHub Desktop.
Save esc/88780a70f9acb6a53f603ebbe5fcc8ec to your computer and use it in GitHub Desktop.
Expose a bug in moto EC2 tag filtering
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