title: Lambda function to filter AWS EC2 instances based on tags?
body: <p>I am trying to create a Lambda function that will filter through all running instances, finding the instances that have certain tags, and then shut those instances down. I am relatively new to using AWS Lambda, so any help would be greatly appreciated. Here is what I have so far, I am currently just trying to get the filter to work as I already know how to shut down the instances in Lambda. I am getting an error that says "module initialization error" currently. Any advice?</p>
  
  <pre><code>import boto3
  ec2 = boto3.resource('ec2')
  
  def lambda_handler(event, context):
      filters = [{
           'Name': 'tag:Application',
           'Values': ['exampleName']
         },
         {
          'Name': 'tag:Vertical',
          'Values': ['exampleVertical']
       }]
  
      instances = ec2.instances.filter(Filters=filters)
  
      RunningInstances = [instance.id for instance in instances]
  
      if len(RunningInstances) &gt; 0:
         print("found instances with tag")
      else:
          print("none found")
  </code></pre>
  
  <p>UPDATE: This code works and can find the instances, the problem was caused because the proper roles were not assigned to the function originally. </p>