I want to search for EC2 instances older than 24 hours old, so that I can clear down only the instances that are likely not being used by anyone for testing.
I'm able to filter for instances spun up on a date, or if I just specify the year I can search for all instances created that year. But I can't find out how to filter instances which were spun up before a given date. Here's what I have:
session = get_aws_session()
ec2 = session.resource("ec2", region_name=REGION)
ssm = session.client("ssm")
instances = list(
ec2.instances.filter(
Filters=[
{"Name": "tag:Environment", "Values": ["test"]},
{"Name": "launch-time", "Values": ["2021-09-21*"]},
]
)
)