) start_pod = EksPodOperator( task_id="run_pod", pod_name="run_pod", cluster_name=CLUSTER_NAME, image="amazon/aws-cli:latest", cmds=["sh", "-c", "echo Test Airflow; date"], labels={"demo": "hello_world"}, get_logs=True, # Delete the pod when it reaches its final state, or the execution is interrupted. is_delete_operator_pod=True, ) # An Amazon EKS cluster can not be deleted with attached resources such as nodegroups or Fargate profiles. # Setting the `force` to `True` will delete any attached resources before deleting the cluster. delete_all = EksDeleteClusterOperator( task_id='delete_fargate_profile_and_cluster', cluster_name=CLUSTER_NAME, force_delete_compute=True, ) await_delete_cluster = EksClusterStateSensor( task_id='wait_for_delete_cluster', cluster_name=CLUSTER_NAME, target_state=ClusterStates.NONEXISTENT, ) (create_cluster_and_fargate_profile >> await_create_fargate_profile >> start_pod >> delete_all >> await_delete_cluster)
max_active_runs=1, tags=['example', 'templated'], # 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: # Create an Amazon EKS Cluster control plane without attaching a compute service. create_cluster = EksCreateClusterOperator( task_id='create_eks_cluster', compute=None, cluster_role_arn="{{ dag_run.conf['cluster_role_arn'] }}", resources_vpc_config="{{ dag_run.conf['resources_vpc_config'] }}", ) await_create_cluster = EksClusterStateSensor( task_id='wait_for_create_cluster', target_state=ClusterStates.ACTIVE, ) create_nodegroup = EksCreateNodegroupOperator( task_id='create_eks_nodegroup', nodegroup_name="{{ dag_run.conf['nodegroup_name'] }}", nodegroup_subnets="{{ dag_run.conf['nodegroup_subnets'] }}", nodegroup_role_arn="{{ dag_run.conf['nodegroup_role_arn'] }}", ) await_create_nodegroup = EksNodegroupStateSensor( task_id='wait_for_create_nodegroup', nodegroup_name="{{ dag_run.conf['nodegroup_name'] }}", target_state=NodegroupStates.ACTIVE, )