title: AWS Glue -- Access Workflow Parameters from Within Job
body: <p>How can I retrieve Glue Workflow parameters from within a glue job? </p>
  
  <p>I have an AWS Glue job of type "python shell" that is triggered periodically from within a glue workflow. </p>
  
  <p>The job's code is to be reused from within a large number of different workflows so I'm looking to retrieve workflow parameters to eliminate the need for redundant jobs.  </p>
  
  <p>The AWS Developers guide provides the following tutorial: 
  <a href="https://docs.aws.amazon.com/glue/latest/dg/workflow-run-properties-code.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/glue/latest/dg/workflow-run-properties-code.html</a></p>
  
  <p>But I've been unsuccessful in getting the sample code to execute without triggering errors. I suspect that this example may only apply to the scala/ pyspark jobs and not to python shell jobs. </p>
  
  <p>I've tried the following code from within the relevant job </p>
  
  <pre><code>import sys
  import boto3
  from awsglue.utils import getResolvedOptions
  
  args = getResolvedOptions(sys.argv, ['JOB_NAME','WORKFLOW_NAME', 'WORKFLOW_RUN_ID'])
  workflow_name = args['WORKFLOW_NAME']
  workflow_run_id = args['WORKFLOW_RUN_ID']
  workflow_params = glue_client.get_workflow_run_properties(Name=workflow_name,
                                      RunId=workflow_run_id)["RunProperties"]
  
  print(workflow_name, workflow_run_id, workflow_params)
  </code></pre>
  
  <p>When I trigger the workflow on demand I receive the following error messages: </p>
  
  <pre><code>&gt; Traceback (most recent call last):
  &gt; File "/tmp/runscript.py", line 115, in &lt;module&gt;
  &gt; runpy.run_path(temp_file_path, run_name='__main__')
  &gt; File "/usr/local/lib/python3.6/runpy.py", line 263, in run_path
  &gt; pkg_name=pkg_name, script_name=fname)
  &gt; File "/usr/local/lib/python3.6/runpy.py", line 96, in _run_module_code
  &gt; mod_name, mod_spec, pkg_name, script_name)
  &gt; File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
  &gt; exec(code, run_globals)
  &gt; File "/tmp/glue-python-scripts-w4fbwl3n/map_etl_python_shell_test_env.py", line 10, in &lt;module&gt;
  &gt; File "/glue/lib/awsglue/utils.py", line 10, in getResolvedOptions
  &gt; parsed, extra = parser.parse_known_args(args)
  &gt; File "/usr/local/lib/python3.6/argparse.py", line 1766, in parse_known_args
  &gt; namespace, args = self._parse_known_args(args, namespace)
  &gt; File "/usr/local/lib/python3.6/argparse.py", line 2001, in _parse_known_args
  ', '.join(required_actions))
  &gt; File "/usr/local/lib/python3.6/argparse.py", line 2393, in error
  &gt; self.exit(2, _('%(prog)s: error: %(message)s\n') % args)
  &gt; File "/usr/local/lib/python3.6/argparse.py", line 2380, in exit
  &gt; _sys.exit(status)
  &gt; SystemExit: 2
  &gt; 
  &gt; During handling of the above exception, another exception occurred:
  &gt;
  &gt; Traceback (most recent call last):
  &gt; File "/tmp/runscript.py", line 134, in &lt;module&gt;
  &gt; raise e_type(e_value).with_tracsback(new_stack)
  &gt; AttributeError: 'SystemExit' object has no attribute 'with_tracsback'
  </code></pre>