

As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.

# Referência de comandos da CLI do Apache Airflow
<a name="airflow-cli-command-reference"></a>

Esta página descreve os comandos da CLI do Apache Airflow compatíveis e não compatíveis no Amazon Managed Workflows para Apache Airflow.

**dica**  
A API REST é mais moderna que a CLI e foi projetada para integração programática com sistemas externos. REST é a forma preferida de interagir com o Apache Airflow.

**Contents**
+ [Pré-requisitos](#airflow-cli-command-prereqs)
  + [Acesso](#access-airflow-ui-prereqs-access)
  + [AWS CLI](#access-airflow-ui-prereqs-cli)
+ [O que mudou?](#airflow-cli-command-changed)
+ [Comandos CLI compatíveis](#airflow-cli-commands)
  + [Comandos compatíveis](#airflow-cli-commands-supported)
  + [Como usar comandos que analisam DAGs](#parsing-support)
+ [Código de exemplo](#airflow-cli-command-examples)
  + [Definir, obter ou excluir uma variável do Apache Airflow v2](#example-airflow-cli-commands-bash)
  + [Adicionar uma configuração ao acionar um DAG](#example-airflow-cli-commands-trigger)
  + [Execute comandos CLI em um túnel SSH para um bastion host](#example-airflow-cli-commands-private)

## Pré-requisitos
<a name="airflow-cli-command-prereqs"></a>

A seção a seguir descreve as etapas preliminares necessárias para usar os comandos e scripts desta página.

### Acesso
<a name="access-airflow-ui-prereqs-access"></a>
+ Conta da AWS acesso AWS Identity and Access Management (IAM) à política de permissões do Amazon MWAA em. [Política de acesso à interface do Apache Airflow: AmazonMWAAWebServerAccess](access-policies.md#web-ui-access)
+ Conta da AWS acesso AWS Identity and Access Management (IAM) à política de permissões do Amazon MWAA. [Política completa de acesso à API e ao console: AmazonMWAAFullApiAccess](access-policies.md#full-access-policy)

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

O AWS Command Line Interface (AWS CLI) é uma ferramenta de código aberto que você pode usar para interagir com AWS serviços usando comandos em seu shell de linha de comando. Para concluir as etapas nesta página, é necessário o seguinte:
+ [AWS CLI — Instale a versão 2](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html).
+ [AWS CLI — Configuração rápida com `aws configure`](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html).

## O que mudou?
<a name="airflow-cli-command-changed"></a>
+ **v3: arquitetura do Airflow**. O Apache Airflow v3 introduz mudanças arquitetônicas revolucionárias para oferecer maior segurança e escalabilidade, além de facilitar a manutenção. Para saber mais, consulte [Atualizar para o Airflow 3](https://airflow.apache.org/docs/apache-airflow/stable/installation/upgrading_to_airflow3.html).
+ **v2: estrutura de comandos da CLI do Airflow**. A CLI do Apache Airflow v2 é organizada para que os comandos relacionados sejam agrupados como subcomandos, o que significa que você precisa atualizar os scripts do Apache Airflow v1 se quiser atualizar para o Apache Airflow v2. Por exemplo, `unpause` no Apache Airflow v1 agora é `dags unpause` no Apache Airflow v2. Para saber mais, consulte as [Alterações da CLI do Airflow](http://airflow.apache.org/docs/apache-airflow/2.0.2/upgrading-to-2.html#airflow-cli-changes-in-2-0) na versão 2.0.

## Comandos CLI compatíveis
<a name="airflow-cli-commands"></a>

A seção a seguir lista os comandos da CLI do Apache Airflow disponíveis no Amazon MWAA.

### Comandos compatíveis
<a name="airflow-cli-commands-supported"></a>

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


| Versões secundárias | Command | 
| --- | --- | 
| v3.0.6, v3.2.1 | [assets details](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#details) | 
| v3.0.6, v3.2.1 | [assets list](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#list) | 
| v3.0.6, v3.2.1 | [assets materialize](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#materialize) | 
| v3.0.6, v3.2.1 | [backfill create](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#create) | 
| v3.0.6, v3.2.1 | [cheat-sheet](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#cheat-sheet) | 
| v3.0.6, v3.2.1 | [connections add](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#add) | 
| v3.0.6, v3.2.1 | [connections delete](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete) | 
| v3.0.6, v3.2.1 | [dags delete](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete_repeat1) | 
| v3.0.6, v3.2.1 | [dags list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat2) | 
| v3.0.6, v3.2.1 | [dags list-jobs](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list-jobs) | 
| v3.0.6, v3.2.1 | [dags list-import-errors](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#list-import-errors) | 
| v3.0.6, v3.2.1 | [dags list-runs](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list-runs) | 
| v3.0.6, v3.2.1 | [dags next-execution](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#next-execution) | 
| v3.0.6, v3.2.1 | [dags pause](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#pause) | 
| v3.0.6, v3.2.1 | [dags report](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#report) | 
| v3.0.6, v3.2.1 | [dags reserialize](https://airflow.apache.org/docs/apache-airflow/2.4.3/cli-and-env-variables-ref.html#reserialize) | 
| v3.0.6, v3.2.1 | [dags show](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#show) | 
| v3.0.6, v3.2.1 | [dags state](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#state) | 
| v3.0.6, v3.2.1 | [dags test](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#test) | 
| v3.0.6, v3.2.1 | [dags trigger](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#trigger) | 
| v3.0.6, v3.2.1 | [dags unpause](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#unpause) | 
| v3.0.6, v3.2.1 | [db clean](https://airflow.apache.org/docs/apache-airflow/2.4.3/cli-and-env-variables-ref.html#clean) | 
| v3.0.6, v3.2.1 | [providers behaviours](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#behaviours) | 
| v3.0.6, v3.2.1 | [providers get](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#get_repeat2) | 
| v3.0.6, v3.2.1 | [providers hooks](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#hooks) | 
| v3.0.6, v3.2.1 | [providers links](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#links) | 
| v3.0.6, v3.2.1 | [providers list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat4) | 
| v3.0.6, v3.2.1 | [notificações de provedores](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#notifications) | 
| v3.0.6, v3.2.1 | [providers secrets](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#secrets) | 
| v3.0.6, v3.2.1 | [providers triggerer](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#triggerer) | 
| v3.0.6, v3.2.1 | [providers widgets](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#widgets) | 
| v3.0.6, v3.2.1 | [roles add-perms](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#add-perms) | 
| v3.0.6, v3.2.1 | [roles del-perms](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#del-perms) | 
| v3.0.6, v3.2.1 | [roles create](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#create) | 
| v3.0.6, v3.2.1 | [roles list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat5) | 
| v3.0.6, v3.2.1 | [tasks clear](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#clear) | 
| v3.0.6, v3.2.1 | [tasks failed-deps](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#failed-deps) | 
| v3.0.6, v3.2.1 | [tasks list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat6) | 
| v3.0.6, v3.2.1 | [tasks render](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#render) | 
| v3.0.6, v3.2.1 | [tasks state](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#state_repeat1) | 
| v3.0.6, v3.2.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) | 
| v3.0.6, v3.2.1 | [tasks test](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#test_repeat1) | 
| v3.0.6, v3.2.1 | [variables delete](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete_repeat4) | 
| v3.0.6, v3.2.1 | [variables get](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#get_repeat3) | 
| v3.0.6, v3.2.1 | [variables set](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#set_repeat1) | 
| v3.0.6, v3.2.1 | [variables list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat8) | 
| v3.0.6, v3.2.1 | [version](http://airflow.apache.org/docs/apache-airflow/1.10.12/cli-ref.html#version) | 

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


| Versões secundárias | Command | 
| --- | --- | 
| v2.0\+ | [cheat-sheet](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#cheat-sheet) | 
| v2.0\+ | [connections add](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#add) | 
| v2.0\+ | [connections delete](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete) | 
| v2.2\+ ([nota](#parsing-support)) | [dags backfill](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#backfill) | 
| v2.0\+ | [dags delete](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete_repeat1) | 
| v2.2\+ ([nota](#parsing-support)) | [dags list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat2) | 
| v2.0\+ | [dags list-jobs](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list-jobs) | 
| v2.6\+ | [dags list-import-errors](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#list-import-errors) | 
| v2.2\+ ([nota](#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\+ ([nota](#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\+ | [dags pause](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#pause) | 
| v2.0\+ | [dags report](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#report) | 
| v2.4\+ | [dags reserialize](https://airflow.apache.org/docs/apache-airflow/2.4.3/cli-and-env-variables-ref.html#reserialize) | 
| v2.0\+ | [dags show](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#show) | 
| v2.0\+ | [dags state](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#state) | 
| v2.0\+ | [dags test](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#test) | 
| v2.0\+ | [dags trigger](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#trigger) | 
| v2.0\+ | [dags unpause](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#unpause) | 
| v2.4\+ | [db clean](https://airflow.apache.org/docs/apache-airflow/2.4.3/cli-and-env-variables-ref.html#clean) | 
| v2.0\+ | [providers behaviours](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#behaviours) | 
| v2.0\+ | [providers get](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#get_repeat2) | 
| v2.0\+ | [providers hooks](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#hooks) | 
| v2.0\+ | [providers links](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#links) | 
| v2.0\+ | [providers list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat4) | 
| v2.8\+ | [notificações de provedores](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#notifications) | 
| v2.6\+ | [providers secrets](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#secrets) | 
| v2.7\+ | [providers triggerer](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#triggerer) | 
| v2.0\+ | [providers widgets](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#widgets) | 
| v2.6\+ | [roles add-perms](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#add-perms) | 
| v2.6\+ | [roles del-perms](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#del-perms) | 
| v2.6\+ | [roles create](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#create) | 
| v2.0\+ | [roles list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat5) | 
| v2.0\+ | [tasks clear](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#clear) | 
| v2.0\+ | [tasks failed-deps](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#failed-deps) | 
| v2.0\+ | [tasks list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat6) | 
| v2.0\+ | [tasks render](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#render) | 
| v2.0\+ | [tasks run](https://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#run) | 
| v2.0\+ | [tasks state](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#state_repeat1) | 
| v2.0\+ | [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\+ | [tasks test](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#test_repeat1) | 
| v2.0\+ | [variables delete](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete_repeat4) | 
| v2.0\+ | [variables get](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#get_repeat3) | 
| v2.0\+ | [variables set](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#set_repeat1) | 
| v2.0\+ | [variables list](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat8) | 
| v2.0\+ | [version](http://airflow.apache.org/docs/apache-airflow/1.10.12/cli-ref.html#version) | 

------

### Como usar comandos que analisam DAGs
<a name="parsing-support"></a>

Se seu ambiente estiver executando o Apache Airflow v2.0.2, os comandos da CLI que analisam DAGs falharão se o DAG usar plug-ins que dependem de pacotes instalados por meio de um `requirements.txt`:

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

Você pode usar estes comandos da CLI se seus DAGs não usarem plug-ins que dependam de pacotes instalados por meio de um `requirements.txt`.

## Código de exemplo
<a name="airflow-cli-command-examples"></a>

A seção a seguir contém exemplos de maneiras diferentes de usar a CLI do Apache Airflow.

### Definir, obter ou excluir uma variável do Apache Airflow v2
<a name="example-airflow-cli-commands-bash"></a>

É possível usar o código de exemplo a seguir para definir, obter ou excluir uma variável no formato de `<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
```

### Adicionar uma configuração ao acionar um DAG
<a name="example-airflow-cli-commands-trigger"></a>

Você pode usar o exemplo de código a seguir com o Apache Airflow v2 para adicionar uma configuração ao acionar um DAG, como `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)
```

### Execute comandos CLI em um túnel SSH para um bastion host
<a name="example-airflow-cli-commands-private"></a>

Use o exemplo a seguir para executar comandos da Airflow CLI usando um proxy de túnel SSH para um bastion host Linux.

**Como usar 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}}
   ```