Using Airflow macro outside of operators

Viewed 4160

Is there any way to use Airflow macro outside of any operators?

For example, in the DAG I have an action:

datestamp = '{{ ds }}'

print(datestamp) # prints string not the date when I run it for any date

scanner = S3KeySensor(
        task_id='scanner',
        poke_interval=60,
        timeout=24 * 60 * 60,
        soft_fail=False,
        wildcard_match=True,
        bucket_key=getPath() + datestamp, #datestamp correctly replaced with execution date
        bucket_name=bucketName,
        dag=dag)

So when calling scanner, "ds" value gets replaced with execution date which is expected, but I want to use "ds" value in some other places. But in that case, it doesn't replace value, instead it gets entire string as "{{ ds }}". In the above example. print statement prints "{{ ds }}" not the execution date.

2 Answers
Related