title: AWS Glue Pyspark Transformation Filter API not working
body: <p>I am new to AWS Glue and Python.  Trying to apply a Filer.apply function for a dynamicFrame datasource0 in filter3frame.  The job run failed and I am getting that filter_sex function is not defined in the logs.  Exact error: "NameError: filter_sex is not defined".  Can anyone tell what I am doing wrong?</p>
  
  <pre><code>import sys
  from awsglue.transforms import *
  from awsglue.utils import getResolvedOptions
  from pyspark.context import SparkContext
  from awsglue.context import GlueContext
  from awsglue.job import Job
  
  ## @params: [JOB_NAME]
  args = getResolvedOptions(sys.argv, ['JOB_NAME'])
  
  sc = SparkContext()
  glueContext = GlueContext(sc)
  spark = glueContext.spark_session
  job = Job(glueContext)
  job.init(args['JOB_NAME'], args)
  
  datasource0 = glueContext.create_dynamic_frame.from_catalog(database = "amssurvey", table_name = "amssurvey", transformation_ctx = "datasource0")
  
  
  filter1frame = Filter.apply(frame=datasource0, f=lambda x:x['citizen'] in ["US"])
  
  filter2frame = Filter.apply(frame=datasource0, f=lambda x:x['count'] &gt; 50)
  
  filter3frame = Filter.apply(frame=datasource0, f=filter_sex(datasource0))
  
  
  
  
  
  
  
  filter1_op = glueContext.write_dynamic_frame.from_options(frame = filter1frame, connection_type = "s3", connection_options = {"path": "s3://asgqatestautomation3/SourceFiles/filter1_op"}, format = "csv", transformation_ctx = "filter1_op")
  filter2_op = glueContext.write_dynamic_frame.from_options(frame = filter2frame, connection_type = "s3", connection_options = {"path": "s3://asgqatestautomation3/SourceFiles/filter2_op"}, format = "csv", transformation_ctx = "filter2_op")
  filter3_op = glueContext.write_dynamic_frame.from_options(frame = filter3frame, connection_type = "s3", connection_options = {"path": "s3://asgqatestautomation3/SourceFiles/filter3_op"}, format = "csv", transformation_ctx = "filter3_op")
  job.commit()
  
  
  
  def filter_sex(item):
      if item['sex'] == 'Male':
          return True
      else:
          return False
  </code></pre>