Skip to content

Commit e64e9d9

Browse files
Add MWAA module and example (#585)
Co-authored-by: Bryant Biggs <[email protected]>
1 parent a7b549b commit e64e9d9

File tree

11 files changed

+521
-0
lines changed

11 files changed

+521
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ If you are interested in contributing to EKS Blueprints, see the [Contribution g
220220
| <a name="output_cluster_security_group_arn"></a> [cluster\_security\_group\_arn](#output\_cluster\_security\_group\_arn) | Amazon Resource Name (ARN) of the cluster security group |
221221
| <a name="output_cluster_security_group_id"></a> [cluster\_security\_group\_id](#output\_cluster\_security\_group\_id) | EKS Control Plane Security Group ID |
222222
| <a name="output_configure_kubectl"></a> [configure\_kubectl](#output\_configure\_kubectl) | Configure kubectl: make sure you're logged in with the correct AWS profile and run the following command to update your kubeconfig |
223+
| <a name="output_eks_cluster_arn"></a> [eks\_cluster\_arn](#output\_eks\_cluster\_arn) | Amazon EKS Cluster Name |
223224
| <a name="output_eks_cluster_certificate_authority_data"></a> [eks\_cluster\_certificate\_authority\_data](#output\_eks\_cluster\_certificate\_authority\_data) | Base64 encoded certificate data required to communicate with the cluster |
224225
| <a name="output_eks_cluster_endpoint"></a> [eks\_cluster\_endpoint](#output\_eks\_cluster\_endpoint) | Endpoint for your Kubernetes API server |
225226
| <a name="output_eks_cluster_id"></a> [eks\_cluster\_id](#output\_eks\_cluster\_id) | Amazon EKS Cluster Name |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
## EKS Cluster w/ Amazon Manged Workflows for Apache Airflopw (MWAA)
2+
3+
The example demonstrates how to use Amazon Managed Workflows for Apache Airflow (MWAA) with Amazon EKS.
4+
5+
This example was originated from the steps provided on MWAA documentation on the link below:
6+
[mwaa-eks-example](https://docs.aws.amazon.com/mwaa/latest/userguide/mwaa-eks-example.html)
7+
8+
### Considerations
9+
10+
1. Ideally we recommend adding the steps to sync requirements/sync dags to the MWAA S3 Bucket as part of a CI/CD pipeline. Generally Dags development have a different lifecycle than the Terraform code to provision infrastructure.
11+
However for simplicity we are providing steps for that using Terraform running AWS CLI commands on null_resource.
12+
13+
## Prerequisites:
14+
15+
Ensure that you have the following tools installed locally:
16+
17+
1. [aws cli](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)
18+
2. [kubectl](https://Kubernetes.io/docs/tasks/tools/)
19+
3. [terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli)
20+
21+
## Deploy
22+
23+
To provision this example:
24+
25+
```sh
26+
terraform init
27+
terraform apply
28+
```
29+
30+
Enter `yes` at command prompt to apply
31+
32+
33+
## Validate
34+
35+
The following command will update the `kubeconfig` on your local machine and allow you to interact with your EKS Cluster using `kubectl` to validate the deployment.
36+
37+
1. Run `update-kubeconfig` command:
38+
39+
```sh
40+
aws eks --region <REGION> update-kubeconfig --name <CLUSTER_NAME>
41+
```
42+
43+
2. List the nodes running currently
44+
45+
```sh
46+
kubectl get nodes
47+
48+
# Output should look like below
49+
NAME STATUS ROLES AGE VERSION
50+
ip-10-0-30-125.us-west-2.compute.internal Ready <none> 2m19s v1.22.9-eks-810597c
51+
```
52+
53+
3. Log into Apache Airflow UI
54+
55+
- Open the Environments page on the Amazon MWAA console
56+
- Choose an environment
57+
- Under the `Details` section, click the link for the Airflow UI
58+
59+
4. Triger the DAG workflow to execute
60+
61+
In the Airflow UI, enable the example and then trigger it.
62+
63+
![Enable the DAG kubernetes_pod_example ](images/kubernetes_pod_example_dag.png)
64+
65+
![Trigger the DAG kubernetes_pod_example ](images/dag_tree.png)
66+
67+
5. Verify that the pod was executed successfully
68+
69+
After it runs and completes successfully, use the following command to verify the pod:
70+
71+
```sh
72+
kubectl get pods -n mwaa
73+
```
74+
75+
You should see output similar to the following:
76+
77+
```sh
78+
NAME READY STATUS RESTARTS AGE
79+
mwaa-pod-test.4bed823d645844bc8e6899fd858f119d 0/1 Completed 0 25s
80+
```
81+
82+
## Destroy
83+
84+
To teardown and remove the resources created in this example:
85+
86+
```sh
87+
terraform destroy -auto-approve
88+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from airflow import DAG
2+
from datetime import datetime
3+
from airflow.providers.cncf.kubernetes.operators.kubernetes_pod import (
4+
KubernetesPodOperator,
5+
)
6+
7+
default_args = {
8+
"owner": "aws",
9+
"depends_on_past": False,
10+
"start_date": datetime(2019, 2, 20),
11+
"provide_context": True,
12+
}
13+
14+
dag = DAG("kubernetes_pod_example", default_args=default_args, schedule_interval=None)
15+
16+
# use a kube_config stored in s3 dags folder for now
17+
kube_config_path = "/usr/local/airflow/dags/kube_config.yaml"
18+
19+
podRun = KubernetesPodOperator(
20+
namespace="mwaa",
21+
image="ubuntu:18.04",
22+
cmds=["bash"],
23+
arguments=["-c", "ls"],
24+
labels={"foo": "bar"},
25+
name="mwaa-pod-test",
26+
task_id="pod-task",
27+
get_logs=True,
28+
dag=dag,
29+
is_delete_operator_pod=False,
30+
config_file=kube_config_path,
31+
in_cluster=False,
32+
cluster_context="mwaa", # Must match kubeconfig context
33+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
kubernetes==11.0.0
2+
apache-airflow-providers-cncf-kubernetes==2.0.2
Loading
Loading

0 commit comments

Comments
 (0)