Skip to content

Commit adbb8dd

Browse files
committed
create dag to execute docker image on ECS Fargate
1 parent 531514f commit adbb8dd

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ENV DEBIAN_FRONTEND noninteractive
1010
ENV TERM linux
1111

1212
# Airflow
13-
ARG AIRFLOW_VERSION=1.10.10
13+
ARG AIRFLOW_VERSION=1.10.11
1414
ENV AIRFLOW_HOME=/usr/local/airflow
1515
ENV AIRFLOW_GPL_UNIDECODE=yes
1616

@@ -66,7 +66,7 @@ RUN set -ex \
6666
&& pip install pyOpenSSL \
6767
&& pip install ndg-httpsclient \
6868
&& pip install pyasn1 \
69-
&& pip install apache-airflow[async,crypto,celery,kubernetes,jdbc,password,postgres,s3,slack]==${AIRFLOW_VERSION} \
69+
&& pip install apache-airflow[async,crypto,celery,kubernetes,jdbc,password,postgres,s3,slack,amazon]==${AIRFLOW_VERSION} \
7070
&& pip install werkzeug==${WERKZEUG_VERSION} \
7171
&& pip install redis==${PYTHON_REDIS_VERSION} \
7272
&& pip install celery[redis]==${CELERY_REDIS_VERSION} \

dags/crypto_extract_dag.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from datetime import datetime
2+
import logging
3+
4+
from airflow import DAG
5+
from airflow.contrib.operators.ecs_operator import ECSOperator
6+
from airflow.models import Variable
7+
8+
logger = logging.getLogger(__name__)
9+
10+
default_args = {
11+
'owner': 'andresionek91',
12+
'start_date': datetime(2020, 5, 20),
13+
'depends_on_past': False,
14+
'provide_context': True
15+
}
16+
17+
execution_date = '{{ ds }}' # Access execution date
18+
19+
with DAG('crypto_extract',
20+
description='DAG to extract Daily Summaries from MercadoBitcoin',
21+
schedule_interval='* 1 * * *',
22+
catchup=True,
23+
default_args=default_args) as dag:
24+
25+
t1 = ECSOperator(
26+
task_id="crypto_extract",
27+
dag=dag,
28+
aws_conn_id="aws_default",
29+
cluster="airflow-dev-ecs-cluster",
30+
task_definition="dev-crypto-extract-image",
31+
launch_type="FARGATE",
32+
overrides={
33+
"containerOverrides": [
34+
{
35+
"name": "dev-crypto-extract-image",
36+
"command": ["python", "main.py", execution_date],
37+
"environment": [
38+
{
39+
'name': 'AWS_ACCESS_KEY_ID',
40+
'value': 'string'
41+
}
42+
]
43+
}
44+
],
45+
},
46+
network_configuration = {
47+
"awsvpcConfiguration": {
48+
"securityGroups": [Variable.get("security-group")],
49+
"subnets": [Variable.get("subnet")],
50+
"assignPublicIp": "ENABLED"
51+
}
52+
}
53+
)
54+
55+
t1

requirements.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ cryptography==2.9.2
33
pandas==0.24.0
44
toolz==0.9.0
55
jinja2==2.11.2
6-
click==7.1.2
6+
click==7.1.2
7+
docker==4.2.0
8+
apache-airflow-backport-providers-amazon==2020.6.24

0 commit comments

Comments
 (0)