
import boto3
from subprocess import call

ec2 = boto3.resource('ec2')

filters = [{'Name': 'instance-state-name', 'Values': ['running']}]
if "EC2_KEY_NAME" in os.environ:
    filters.append({'Name': 'key-name', 'Values': [os.environ['EC2_KEY_NAME']]})

instances = ec2.instances.filter(Filters=filters)

ids = [instance.id for instance in instances]
print("Terminating:", ids)

ec2.instances.filter(InstanceIds=ids).terminate()

##########################################################################


import boto3
import os
from subprocess import call

ec2 = boto3.resource('ec2')

filters = [{'Name': 'instance-state-name', 'Values': ['running']}]
if "EC2_KEY_NAME" in os.environ:
    filters.append({'Name': 'key-name', 'Values': [os.environ['EC2_KEY_NAME']]})

instances = ec2.instances.filter(Filters=filters)

ids = [instance.id for instance in instances]
print("Terminating:", ids)

ec2.instances.filter(InstanceIds=ids).terminate()

##########################################################################

Add import statement for os
Add import statement for os
  
  import boto3
+ import os
  from subprocess import call
  
  ec2 = boto3.resource('ec2')
  
  filters = [{'Name': 'instance-state-name', 'Values': ['running']}]
  if "EC2_KEY_NAME" in os.environ:
      filters.append({'Name': 'key-name', 'Values': [os.environ['EC2_KEY_NAME']]})
  
  instances = ec2.instances.filter(Filters=filters)
  
  ids = [instance.id for instance in instances]
  print("Terminating:", ids)
  
  ec2.instances.filter(InstanceIds=ids).terminate()
  
  ##########################################################################
  
Add import statement for os
## Code Before:

import boto3
from subprocess import call

ec2 = boto3.resource('ec2')

filters = [{'Name': 'instance-state-name', 'Values': ['running']}]
if "EC2_KEY_NAME" in os.environ:
    filters.append({'Name': 'key-name', 'Values': [os.environ['EC2_KEY_NAME']]})

instances = ec2.instances.filter(Filters=filters)

ids = [instance.id for instance in instances]
print("Terminating:", ids)

ec2.instances.filter(InstanceIds=ids).terminate()

##########################################################################

## Instruction:
Add import statement for os
## Code After:

import boto3
import os
from subprocess import call

ec2 = boto3.resource('ec2')

filters = [{'Name': 'instance-state-name', 'Values': ['running']}]
if "EC2_KEY_NAME" in os.environ:
    filters.append({'Name': 'key-name', 'Values': [os.environ['EC2_KEY_NAME']]})

instances = ec2.instances.filter(Filters=filters)

ids = [instance.id for instance in instances]
print("Terminating:", ids)

ec2.instances.filter(InstanceIds=ids).terminate()

##########################################################################
