Question: How can I implement an optional parameter to an AWS Glue Job?

I have created a job that currently have a string parameter (an ISO 8601 date string) as an input that is used in the ETL job. I would like to make this parameter optional, so that the job use a default value if it is not provided (e.g. using [datetime.now](https://docs.python.org/2/library/datetime.html?highlight=datetime#datetime.datetime.now) and [datetime.isoformat](https://docs.python.org/2/library/datetime.html?highlight=datetime#datetime.datetime.isoformat)in my case). I have tried using [getResolvedOptions](https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-crawler-pyspark-extensions-get-resolved-options.html):

```
import sys
from awsglue.utils import getResolvedOptions

args = getResolvedOptions(sys.argv, ['ISO_8601_STRING'])

```

However, when I am not passing an `--ISO_8601_STRING` job parameter I see the following error:

> 
> awsglue.utils.GlueArgumentError: argument --ISO\_8601\_STRING is required
> 
> 
>

Answer: 
Wrapping [matsev's answer](https://stackoverflow.com/a/52298107/2863603) in a function:

```
def get_glue_env_var(key, default="none"):
    if f'--{key}' in sys.argv:
        return getResolvedOptions(sys.argv, [key])[key]
    else:
        return default

```
If you're using the interface, you must provide your parameter names starting with "--" like "--TABLE\_NAME", rather than "TABLE\_NAME", then you can use them like the following (python) code:

```
args = getResolvedOptions(sys.argv, ['JOB_NAME', 'TABLE_NAME'])
table_name = args['TABLE_NAME']

```