Ваш фильтр для тегов неправильный, вам нужно его изменить:
filters = [{
'Name': 'tag:Name',
'Values': ['Shut']
},
{
'Name': 'instance-state-name',
'Values': ['running']
}
]
Вот полный рабочий пример:
import boto3
#define the connection
ec2 = boto3.resource('ec2')
def lambda_handler(event, context):
# Use the filter() method of the instances collection to retrieve
# all running EC2 instances.
filters = [{
'Name': 'tag:Name',
'Values': ['Shut']
},
{
'Name': 'instance-state-name',
'Values': ['running']
}
]
#filter the instances
instances = ec2.instances.filter(Filters=filters)
#locate all running instances
RunningInstances = [instance.id for instance in instances]
#print the instances for logging purposes
#print RunningInstances
#make sure there are actually instances to shut down.
if len(RunningInstances) > 0:
#perform the shutdown
shuttingDown = ec2.instances.filter(
InstanceIds=RunningInstances).stop()
print(shuttingDown)
else:
print("No Instances to shut down")