with DAG(
        dag_id='example_eks_with_fargate_in_one_step',
        schedule_interval=None,
        start_date=datetime(2021, 1, 1),
        tags=['example'],
        catchup=False,
) as dag:

    # [START howto_operator_eks_create_cluster_with_fargate_profile]
    # Create an Amazon EKS cluster control plane and an AWS Fargate compute platform in one step.
    create_cluster_and_fargate_profile = EksCreateClusterOperator(
        task_id='create_eks_cluster_and_fargate_profile',
        cluster_name=CLUSTER_NAME,
        cluster_role_arn=ROLE_ARN,
        resources_vpc_config=VPC_CONFIG,
        compute='fargate',
        fargate_profile_name=FARGATE_PROFILE_NAME,
        # Opting to use the same ARN for the cluster and the pod here,
        # but a different ARN could be configured and passed if desired.
        fargate_pod_execution_role_arn=ROLE_ARN,
    )
    # [END howto_operator_eks_create_cluster_with_fargate_profile]

    await_create_fargate_profile = EksFargateProfileStateSensor(
        task_id='wait_for_create_fargate_profile',
        cluster_name=CLUSTER_NAME,
        fargate_profile_name=FARGATE_PROFILE_NAME,
        target_state=FargateProfileStates.ACTIVE,
    )

    start_pod = EksPodOperator(
        dag_id='example_eks_templated',
        start_date=datetime(2021, 1, 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:

    CLUSTER_NAME = "{{ dag_run.conf['cluster_name'] }}"
    NODEGROUP_NAME = "{{ dag_run.conf['nodegroup_name'] }}"

    # Create an Amazon EKS Cluster control plane without attaching a compute service.
    create_cluster = EksCreateClusterOperator(
        task_id='create_eks_cluster',
        cluster_name=CLUSTER_NAME,
        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',
        cluster_name=CLUSTER_NAME,
        target_state=ClusterStates.ACTIVE,
    )

    create_nodegroup = EksCreateNodegroupOperator(
        task_id='create_eks_nodegroup',
        cluster_name=CLUSTER_NAME,
        nodegroup_name=NODEGROUP_NAME,
        nodegroup_subnets="{{ dag_run.conf['nodegroup_subnets'] }}",
示例#3
0
}

with DAG(
        dag_id='example_eks_with_fargate_profile_dag',
        default_args={'cluster_name': CLUSTER_NAME},
        schedule_interval=None,
        start_date=datetime(2021, 1, 1),
        catchup=False,
        max_active_runs=1,
        tags=['example'],
) as dag:

    # Create an Amazon EKS Cluster control plane without attaching a compute service.
    create_cluster = EksCreateClusterOperator(
        task_id='create_eks_cluster',
        cluster_role_arn=ROLE_ARN,
        resources_vpc_config=VPC_CONFIG,
        compute=None,
    )

    await_create_cluster = EksClusterStateSensor(
        task_id='wait_for_create_cluster',
        target_state=ClusterStates.ACTIVE,
    )

    # [START howto_operator_eks_create_fargate_profile]
    create_fargate_profile = EksCreateFargateProfileOperator(
        task_id='create_eks_fargate_profile',
        pod_execution_role_arn=ROLE_ARN,
        fargate_profile_name=FARGATE_PROFILE_NAME,
        selectors=SELECTORS,
    )
with DAG(
    dag_id='example_eks_with_nodegroup_in_one_step',
    schedule_interval=None,
    start_date=datetime(2021, 1, 1),
    tags=['example'],
    catchup=False,
) as dag:

    # [START howto_operator_eks_create_cluster_with_nodegroup]
    # Create an Amazon EKS cluster control plane and an EKS nodegroup compute platform in one step.
    create_cluster_and_nodegroup = EksCreateClusterOperator(
        task_id='create_eks_cluster_and_nodegroup',
        cluster_name=CLUSTER_NAME,
        nodegroup_name=NODEGROUP_NAME,
        cluster_role_arn=ROLE_ARN,
        nodegroup_role_arn=ROLE_ARN,
        # Opting to use the same ARN for the cluster and the nodegroup here,
        # but a different ARN could be configured and passed if desired.
        resources_vpc_config=VPC_CONFIG,
        # Compute defaults to 'nodegroup' but is called out here for the purposed of the example.
        compute='nodegroup',
    )
    # [END howto_operator_eks_create_cluster_with_nodegroup]

    await_create_nodegroup = EksNodegroupStateSensor(
        task_id='wait_for_create_nodegroup',
        cluster_name=CLUSTER_NAME,
        nodegroup_name=NODEGROUP_NAME,
        target_state=NodegroupStates.ACTIVE,
    )

    start_pod = EksPodOperator(
示例#5
0
        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:
    SUBNETS = os.environ.get('EKS_DEMO_SUBNETS',
                             'subnet-12345ab subnet-67890cd').split(' ')
    VPC_CONFIG = {
        'subnetIds': SUBNETS,
        'endpointPublicAccess': True,
        'endpointPrivateAccess': False,
    }
    # 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=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'] }}",
    )