Jovan Sakovic
06/26/2023, 5:08 PMjob_variables
in a jinja template?Marvin
06/26/2023, 5:09 PM{{ field_name }}
. In your case, you can use {{ name }}
to reference the deployment name in the job_variables
section of your deployment YAML file.
Here's an example of how to use the deployment name in a jinja template within Prefect:
yaml
deployments:
- name: my_deployment
job_variables:
deployment_name: "{{ name }}"
In this example, the deployment_name
variable in the job_variables
section will be populated with the deployment name, which is "my_deployment" in this case. You can find more information about using dynamic values in deployment YAML files in the Prefect documentation.
Now go forth and deploy, my human friend.Jovan Sakovic
06/26/2023, 5:11 PMdeployments:
- name: dbt
version: null
tags: []
description: 'Trigger dbt commands'
entrypoint: prefect/flows/dbt.py:trigger_dbt_flow
parameters: {}
work_pool:
name: ecs-default
work_queue_name: null
job_variables:
image: '{{ build_image.image }}'
execution_role_arn: 'arn:aws:iam::1231231232:role/prefect-flow-run-execution-role'
cloudwatch_logs_options: {
"awslogs-group": "beacon-{{ name }}"
}
schedule: null
Marvin
06/26/2023, 5:12 PMjob_variables
section of the deployment YAML file. However, you can use a workaround by defining a custom variable and using it in your YAML file.
Here's an example of how you can achieve this:
1. Set a custom variable in Prefect:
bash
prefect variables set deployment_name dbt
2. Use the custom variable in your deployment YAML file:
yaml
deployments:
- name: dbt
version: null
tags: []
description: 'Trigger dbt commands'
entrypoint: prefect/flows/dbt.py:trigger_dbt_flow
parameters: {}
work_pool:
name: ecs-default
work_queue_name: null
job_variables:
image: '{{ build_image.image }}'
execution_role_arn: 'arn:aws:iam::1231231232:role/prefect-flow-run-execution-role'
cloudwatch_logs_options: {
"awslogs-group": "beacon-{{ prefect.variables.deployment_name }}"
}
schedule: null
In this example, I've set a custom variable called deployment_name
and used it in the job_variables
section with {{ prefect.variables.deployment_name }}
. This way, you can use the deployment name as a variable in your YAML file.
Keep in mind that this workaround requires you to set the custom variable manually and keep it in sync with the deployment name. It's not an ideal solution, but it should help you achieve your goal.
I hope this helps you in your quest for jinja enlightenment.Jovan Sakovic
06/26/2023, 5:13 PMMarvin
06/26/2023, 5:14 PMjob_variables
section of the deployment YAML file.
However, you can still achieve your goal by using a consistent naming convention for your deployments and custom variables. For example, you can create a custom variable for each deployment with a prefix like deployment_
followed by the deployment name:
1. Set custom variables for each deployment:
bash
prefect variables set deployment_dbt dbt
prefect variables set deployment_another_deployment another_deployment
2. Use the custom variables in your deployment YAML files:
yaml
deployments:
- name: dbt
# ...
work_pool:
# ...
job_variables:
# ...
cloudwatch_logs_options: {
"awslogs-group": "beacon-{{ prefect.variables.deployment_dbt }}"
}
# ...
- name: another_deployment
# ...
work_pool:
# ...
job_variables:
# ...
cloudwatch_logs_options: {
"awslogs-group": "beacon-{{ prefect.variables.deployment_another_deployment }}"
}
# ...
By following this naming convention, you can ensure that each deployment has a corresponding custom variable that defaults to the deployment name. While this approach still requires manual management of custom variables, it provides a more consistent and organized way to handle deployment-specific variables in your Worker config.
I hope this solution brings a smile to your face, even if it's not perfect.