eladkal commented on a change in pull request #21523:
URL: https://github.com/apache/airflow/pull/21523#discussion_r805323142
##########
File path: airflow/providers/amazon/aws/example_dags/example_eks_templated.py
##########
@@ -49,50 +44,53 @@
"""
with DAG(
- dag_id='to-publish-manuals-templated',
- default_args={'cluster_name': "{{ dag_run.conf['cluster_name'] }}"},
+ dag_id='example_eks_templated',
schedule_interval=None,
start_date=datetime(2021, 1, 1),
- catchup=False,
- max_active_runs=1,
tags=['example', 'templated'],
+ catchup=False,
# render_template_as_native_obj=True is what converts the Jinja to Python
objects, instead of a string.
render_template_as_native_obj=True,
) as dag:
- SUBNETS = os.environ.get('EKS_DEMO_SUBNETS', 'subnet-12345ab
subnet-67890cd').split(' ')
- VPC_CONFIG = {
- 'subnetIds': SUBNETS,
- 'endpointPublicAccess': True,
- 'endpointPrivateAccess': False,
- }
+
+ CLUSTER_NAME = "{{ dag_run.conf['cluster_name'] }}"
+ NODEGROUP_NAME = "{{ dag_run.conf['nodegroup_name'] }}"
+ VPC_CONFIG = json.loads("{{ dag_run.conf['resources_vpc_config'] }}")
Review comment:
@ferruzzi you get the error because this line doesn't do what you expect.
You expect `"{{ dag_run.conf['resources_vpc_config'] }}"` to be the Json
define in the beginning of the file:
```
{
"subnetIds": ["subnet-12345ab", "subnet-67890cd"],
"endpointPublicAccess": true,
"endpointPrivateAccess": false
}
```
But this is not what is happening. The Jinja engine runs only in templated
fields of operators. It does not run in top level python code. So when you
execute `json.loads` you actually execute it on the string that you wrote.
If you will run in your python console :
`json.loads("{{ dag_run.conf['resources_vpc_config'] }}")`
You will see it will give you :
`json.decoder.JSONDecodeError: Expecting property name enclosed in double
quotes: line 1 column 2 (char 1)`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]