

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# Apache Airflow CLI 명령 참조
<a name="airflow-cli-command-reference"></a>

이 주제에서는 Amazon Managed Workflows for Apache Airflow에서 지원되는 Apache Airflow CLI 명령과 지원되지 않는 Apache Airflow CLI 명령을 설명합니다.

**작은 정보**  
REST API는 CLI보다 최신이며 외부 시스템과 프로그래밍 방식으로 통합하도록 설계되었습니다. REST는 Apache Airflow와의 상호 작용에 선호되는 방법입니다.

**Contents**
+ [사전 조건](#airflow-cli-command-prereqs)
  + [액세스](#access-airflow-ui-prereqs-access)
  + [AWS CLI](#access-airflow-ui-prereqs-cli)
+ [무엇이 변경되었나요?](#airflow-cli-command-changed)
+ [지원되는 CLI 명령](#airflow-cli-commands)
  + [지원되는 명령](#airflow-cli-commands-supported)
  + [DAG를 구문 분석하는 명령 사용](#parsing-support)
+ [샘플 코드](#airflow-cli-command-examples)
  + [Apache Airflow v2 변수 설정, 가져오기 또는 삭제](#example-airflow-cli-commands-bash)
  + [DAG를 트리거할 때 구성 추가](#example-airflow-cli-commands-trigger)
  + [Bastion Host에 대한 SSH 터널에서 CLI 명령 실행](#example-airflow-cli-commands-private)

## 사전 조건
<a name="airflow-cli-command-prereqs"></a>

다음 섹션에서는 이 페이지의 명령과 스크립트를 사용하는 데 필요한 예비 단계를 설명합니다.

### 액세스
<a name="access-airflow-ui-prereqs-access"></a>
+ Amazon MWAA 권한 정책 [Apache Airflow UI 액세스 정책: AmazonMWAAWebServerAccess](access-policies.md#web-ui-access)에 대한 AWS Identity and Access Management(IAM)의 AWS 계정 계정 액세스
+ Amazon MWAA 권한 정책 [전체 API 및 콘솔 액세스 정책: AmazonMWAFullaPiAccess](access-policies.md#full-access-policy)에 대한 AWS Identity and Access Management(IAM)의 AWS 계정 계정 액세스

### AWS CLI
<a name="access-airflow-ui-prereqs-cli"></a>

AWS Command Line Interface(AWS CLI)는 명령줄 쉘의 명령을 사용하여 AWS 서비스와 상호 작용할 수 있는 오픈 소스 도구입니다. 이 페이지에서 단계를 완료하려면 다음이 필요합니다.
+ [AWS CLI - 버전 2 설치](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)
+ [AWS CLI - `aws configure`을 통한 빠른 구성](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html).

## 무엇이 변경되었나요?
<a name="airflow-cli-command-changed"></a>
+ **v3: Airflow 아키텍처**. Apache Airflow v3는 보안 및 확장성을 개선하고 유지 관리를 더 쉽게 만들기 위해 주요 아키텍처 변경을 도입합니다. 자세한 내용은 [Airflow 3로 업그레이드](https://airflow.apache.org/docs/apache-airflow/stable/installation/upgrading_to_airflow3.html)를 참조하세요.
+ **v2: Airflow CLI 명령 구조**. Apache Airflow v2 CLI는 관련 명령이 하위 명령으로 그룹화되도록 구성되어 있습니다. 이는 Apache Airflow v2로 업그레이드하려면 Apache Airflow v1 스크립트를 업데이트해야 한다는 의미입니다. 예를 들어, Apache Airflow v1의 `unpause`는 Apache Airflow v2의 `dags unpause`입니다. 자세한 내용은 [2.0의 Airflow CLI 변경 사항](http://airflow.apache.org/docs/apache-airflow/2.0.2/upgrading-to-2.html#airflow-cli-changes-in-2-0)을 참조하세요.

## 지원되는 CLI 명령
<a name="airflow-cli-commands"></a>

다음 섹션에는 Amazon MWAA에서 사용할 수 있는 Apache Airflow CLI 명령이 나와 있습니다.

### 지원되는 명령
<a name="airflow-cli-commands-supported"></a>

------
#### [ Apache Airflow v3 ]


| 마이너 버전 | Command | 
| --- | --- | 
|  v3.0.6  |  [assets details](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#details)  | 
|  v3.0.6  |  [assets list](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#list)  | 
|  v3.0.6  |  [assets materialize](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#materialize)  | 
|  v3.0.6  |  [backfill create](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#create)  | 
|  v3.0.6  |  [cheat-sheet](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#cheat-sheet)  | 
|  v3.0.6  |  [connections add](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#add)  | 
|  v3.0.6  |  [connections delete](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete)  | 
|  v3.0.6  |  [dags delete](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete_repeat1)  | 
|  v3.0.6  |  [dags list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat2)  | 
|  v3.0.6  |  [dags list-jobs](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list-jobs)  | 
|  v3.0.6  |  [dags list-import-errors](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#list-import-errors)  | 
|  v3.0.6  |  [dags list-runs](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list-runs)  | 
|  v3.0.6  |  [dags next-execution](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#next-execution)  | 
|  v3.0.6  |  [dags pause](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#pause)  | 
|  v3.0.6  |  [dags report](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#report)  | 
|  v3.0.6  |  [dags reserialize](https://airflow.apache.org/docs/apache-airflow/2.4.3/cli-and-env-variables-ref.html#reserialize)  | 
|  v3.0.6  |  [dags show](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#show)  | 
|  v3.0.6  |  [dags state](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#state)  | 
|  v3.0.6  |  [dags test](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#test)  | 
|  v3.0.6  |  [dags trigger](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#trigger)  | 
|  v3.0.6  |  [dags unpause](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#unpause)  | 
|  v3.0.6  |  [db clean](https://airflow.apache.org/docs/apache-airflow/2.4.3/cli-and-env-variables-ref.html#clean)  | 
|  v3.0.6  |  [providers behaviours](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#behaviours)  | 
|  v3.0.6  |  [providers get](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#get_repeat2)  | 
|  v3.0.6  |  [providers hooks](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#hooks)  | 
|  v3.0.6  |  [providers links](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#links)  | 
|  v3.0.6  |  [providers list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat4)  | 
|  v3.0.6  |  [providers notifications](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#notifications)  | 
|  v3.0.6  |  [providers secrets](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#secrets)  | 
|  v3.0.6  |  [providers triggerer](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#triggerer)  | 
|  v3.0.6  |  [providers widgets](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#widgets)  | 
|  v3.0.6  |  [roles add-perms](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#add-perms)  | 
|  v3.0.6  |  [roles del-perms](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#del-perms)  | 
|  v3.0.6  |  [roles create](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#create)  | 
|  v3.0.6  |  [roles list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat5)  | 
|  v3.0.6  |  [tasks clear](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#clear)  | 
|  v3.0.6  |  [tasks failed-deps](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#failed-deps)  | 
|  v3.0.6  |  [tasks list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat6)  | 
|  v3.0.6  |  [tasks render](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#render)  | 
|  v3.0.6  |  [tasks state](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#state_repeat1)  | 
|  v3.0.6  |  [tasks states-for-dag-run](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#states-for-dag-run)  | 
|  v3.0.6  |  [tasks test](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#test_repeat1)  | 
|  v3.0.6  |  [variables delete](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete_repeat4)  | 
|  v3.0.6  |  [variables get](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#get_repeat3)  | 
|  v3.0.6  |  [variables set](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#set_repeat1)  | 
|  v3.0.6  |  [variables list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat8)  | 
|  v3.0.6  |  [version](http://airflow.apache.org/docs/apache-airflow/1.10.12/cli-ref.html#version)  | 

------
#### [ Apache Airflow v2 ]


| 마이너 버전 | Command | 
| --- | --- | 
|  v2.0\$1  |  [cheat-sheet](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#cheat-sheet)  | 
|  v2.0\$1  |  [connections add](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#add)  | 
|  v2.0\$1  |  [connections delete](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete)  | 
|  v2.2\$1([참고](#parsing-support))  |  [dags backfill](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#backfill)  | 
|  v2.0\$1  |  [dags delete](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete_repeat1)  | 
|  v2.2\$1([참고](#parsing-support))  |  [dags list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat2)  | 
|  v2.0\$1  |  [dags list-jobs](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list-jobs)  | 
|  v2.6\$1  |  [dags list-import-errors](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#list-import-errors)  | 
|  v2.2\$1([참고](#parsing-support))  |  [dags list-runs](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list-runs)  | 
|  v2.2\$1([참고](#parsing-support))  |  [dags next-execution](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#next-execution)  | 
|  v2.0\$1  |  [dags pause](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#pause)  | 
|  v2.0\$1  |  [dags report](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#report)  | 
|  v2.4\$1  |  [dags reserialize](https://airflow.apache.org/docs/apache-airflow/2.4.3/cli-and-env-variables-ref.html#reserialize)  | 
|  v2.0\$1  |  [dags show](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#show)  | 
|  v2.0\$1  |  [dags state](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#state)  | 
|  v2.0\$1  |  [dags test](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#test)  | 
|  v2.0\$1  |  [dags trigger](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#trigger)  | 
|  v2.0\$1  |  [dags unpause](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#unpause)  | 
|  v2.4\$1  |  [db clean](https://airflow.apache.org/docs/apache-airflow/2.4.3/cli-and-env-variables-ref.html#clean)  | 
|  v2.0\$1  |  [providers behaviours](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#behaviours)  | 
|  v2.0\$1  |  [providers get](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#get_repeat2)  | 
|  v2.0\$1  |  [providers hooks](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#hooks)  | 
|  v2.0\$1  |  [providers links](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#links)  | 
|  v2.0\$1  |  [providers list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat4)  | 
|  v2.8 이상  |  [providers notifications](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#notifications)  | 
|  v2.6\$1  |  [providers secrets](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#secrets)  | 
|  v2.7\$1  |  [providers triggerer](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#triggerer)  | 
|  v2.0\$1  |  [providers widgets](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#widgets)  | 
|  v2.6\$1  |  [roles add-perms](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#add-perms)  | 
|  v2.6\$1  |  [roles del-perms](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#del-perms)  | 
|  v2.6\$1  |  [roles create](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#create)  | 
|  v2.0\$1  |  [roles list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat5)  | 
|  v2.0\$1  |  [tasks clear](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#clear)  | 
|  v2.0\$1  |  [tasks failed-deps](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#failed-deps)  | 
|  v2.0\$1  |  [tasks list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat6)  | 
|  v2.0\$1  |  [tasks render](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#render)  | 
|  v2.0\$1  |  [tasks run](https://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#run)  | 
|  v2.0\$1  |  [tasks state](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#state_repeat1)  | 
|  v2.0\$1  |  [tasks states-for-dag-run](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#states-for-dag-run)  | 
|  v2.0\$1  |  [tasks test](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#test_repeat1)  | 
|  v2.0\$1  |  [variables delete](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete_repeat4)  | 
|  v2.0\$1  |  [variables get](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#get_repeat3)  | 
|  v2.0\$1  |  [variables set](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#set_repeat1)  | 
|  v2.0\$1  |  [variables list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat8)  | 
|  v2.0\$1  |  [version](http://airflow.apache.org/docs/apache-airflow/1.10.12/cli-ref.html#version)  | 

------

### DAG를 구문 분석하는 명령 사용
<a name="parsing-support"></a>

환경에서 Apache Airflow v2.0.2를 실행하는 경우 DAG가 `requirements.txt`를 통해 설치된 패키지에 의존하는 플러그인을 사용한다면 DAG를 구문 분석하는 CLI 명령이 실패합니다.

**Apache Airflow v2.0.2**
+ `dags backfill`
+ `dags list`
+ `dags list-runs`
+ `dags next-execution`

DAG가 `requirements.txt`를 통해 설치된 패키지에 의존하는 플러그인을 사용하지 않으면 이러한 CLI 명령을 사용할 수 있습니다.

## 샘플 코드
<a name="airflow-cli-command-examples"></a>

다음 섹션에는 Apache Airflow CLI를 사용하는 여러 방법의 예제가 나와 있습니다.

### Apache Airflow v2 변수 설정, 가져오기 또는 삭제
<a name="example-airflow-cli-commands-bash"></a>

다음 샘플 코드를 사용하여 `<script> <mwaa env name> get | set | delete <variable> <variable value> </variable> </variable>`의 형식으로 변수를 설정, 가져오기 또는 삭제할 수 있습니다.

```
[ $# -eq 0 ] && echo "Usage: $0 MWAA environment name " && exit

if [[ $2 == "" ]]; then
    dag="variables list"

elif  [ $2 == "get" ] ||  [ $2 == "delete" ] ||  [ $2 == "set" ]; then
    dag="variables $2 $3 $4 $5"

else
    echo "Not a valid command"
    exit 1
fi

CLI_JSON=$(aws mwaa --region $AWS_REGION create-cli-token --name $1) \
    && CLI_TOKEN=$(echo $CLI_JSON | jq -r '.CliToken') \
    && WEB_SERVER_HOSTNAME=$(echo $CLI_JSON | jq -r '.WebServerHostname') \
    && CLI_RESULTS=$(curl --request POST "https://$WEB_SERVER_HOSTNAME/aws_mwaa/cli" \
    --header "Authorization: Bearer $CLI_TOKEN" \
    --header "Content-Type: text/plain" \
    --data-raw "$dag" ) \
    && echo "Output:" \
    && echo $CLI_RESULTS | jq -r '.stdout' | base64 --decode \
    && echo "Errors:" \
    && echo $CLI_RESULTS | jq -r '.stderr' | base64 --decode
```

### DAG를 트리거할 때 구성 추가
<a name="example-airflow-cli-commands-trigger"></a>

Apache Airflow v2에서 다음 샘플 코드를 사용하여 DAG를 트리거할 때 `airflow trigger_dag 'dag_name' —conf '{"key":"value"}'`과 같이 구성을 추가할 수 있습니다.

```
import boto3
import json
import requests 
import base64
				
  mwaa_env_name = 'YOUR_ENVIRONMENT_NAME'
  dag_name = 'YOUR_DAG_NAME'
  key = "YOUR_KEY"
  value = "YOUR_VALUE"
  conf = "{\"" + key + "\":\"" + value + "\"}"
				
  client = boto3.client('mwaa')
				
  mwaa_cli_token = client.create_cli_token(
    Name=mwaa_env_name
  )
				
  mwaa_auth_token = 'Bearer ' + mwaa_cli_token['CliToken']
  mwaa_webserver_hostname = 'https://{0}/aws_mwaa/cli'.format(mwaa_cli_token['WebServerHostname'])
  raw_data = "trigger_dag {0} -c '{1}'".format(dag_name, conf)
				
  mwaa_response = requests.post(
    mwaa_webserver_hostname,
    headers={
      'Authorization': mwaa_auth_token,
      'Content-Type': 'text/plain'
    },
    data=raw_data
  )
				
  mwaa_std_err_message = base64.b64decode(mwaa_response.json()['stderr']).decode('utf8')
  mwaa_std_out_message = base64.b64decode(mwaa_response.json()['stdout']).decode('utf8')
				
  print(mwaa_response.status_code)
  print(mwaa_std_err_message)
  print(mwaa_std_out_message)
```

### Bastion Host에 대한 SSH 터널에서 CLI 명령 실행
<a name="example-airflow-cli-commands-private"></a>

다음 예제를 사용하여 Linux Bastion Host에 대한 SSH 터널 프록시를 사용하여 Airflow CLI 명령을 실행합니다.

**curl 사용**

1. 

   ```
   ssh -D 8080 -f -C -q -N YOUR_USER@YOUR_BASTION_HOST
   ```

1. 

   ```
   curl -x socks5h://0:8080 --request POST https://YOUR_HOST_NAME/aws_mwaa/cli --header YOUR_HEADERS --data-raw YOUR_CLI_COMMAND
   ```