

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# Riferimento ai comandi CLI Apache Airflow
<a name="airflow-cli-command-reference"></a>

Questo argomento descrive i comandi CLI di Apache Airflow supportati e non supportati su Amazon Managed Workflows for Apache Airflow.

**Suggerimento**  
L'API REST è più moderna della CLI ed è progettata per l'integrazione programmatica con sistemi esterni. REST è il modo preferito di interagire con Apache Airflow.

**Contents**
+ [Prerequisiti](#airflow-cli-command-prereqs)
  + [Accesso](#access-airflow-ui-prereqs-access)
  + [AWS CLI](#access-airflow-ui-prereqs-cli)
+ [Cosa è cambiato?](#airflow-cli-command-changed)
+ [Comandi CLI supportati](#airflow-cli-commands)
  + [Comandi supportati](#airflow-cli-commands-supported)
  + [Utilizzo di comandi che analizzano DAGs](#parsing-support)
+ [Codice di esempio](#airflow-cli-command-examples)
  + [Imposta, ottieni o elimina una variabile Apache Airflow v2](#example-airflow-cli-commands-bash)
  + [Aggiungere una configurazione quando si attiva un DAG](#example-airflow-cli-commands-trigger)
  + [Esegui i comandi CLI su un tunnel SSH verso un host bastion](#example-airflow-cli-commands-private)

## Prerequisiti
<a name="airflow-cli-command-prereqs"></a>

La sezione seguente descrive i passaggi preliminari necessari per utilizzare i comandi e gli script in questa pagina.

### Accesso
<a name="access-airflow-ui-prereqs-access"></a>
+ Account AWS access in AWS Identity and Access Management (IAM) alla policy di autorizzazione di Amazon MWAA in. [Politica di accesso all'interfaccia utente di Apache Airflow: Amazon MWAAWeb ServerAccess](access-policies.md#web-ui-access)
+ Account AWS accesso AWS Identity and Access Management (IAM) alla policy di autorizzazione di Amazon MWAA. [Politica completa di accesso all'API e alla console: Amazon MWAAFull ApiAccess](access-policies.md#full-access-policy)

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

Il AWS Command Line Interface (AWS CLI) è uno strumento open source che puoi usare per interagire con i AWS servizi utilizzando i comandi nella shell della riga di comando. Per completare la procedura descritta in questa pagina, è necessario quanto segue:
+ [AWS CLI — Installa la versione 2](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html).
+ [AWS CLI — Configurazione rapida con `aws configure`](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html).

## Cosa è cambiato?
<a name="airflow-cli-command-changed"></a>
+ **v3: Architettura Airflow**. Apache Airflow v3 introduce importanti modifiche all'architettura per fornire maggiore sicurezza e scalabilità e per semplificare la manutenzione. [Per ulteriori informazioni, consulta Aggiornamento ad Airflow 3.](https://airflow.apache.org/docs/apache-airflow/stable/installation/upgrading_to_airflow3.html)
+ **v2: Struttura dei comandi CLI Airflow**. L'interfaccia della riga di comando di Apache Airflow v2 è organizzata in modo che i comandi correlati siano raggruppati come sottocomandi, il che significa che è necessario aggiornare gli script di Apache Airflow v1 se si desidera eseguire l'aggiornamento ad Apache Airflow v2. Ad esempio, `unpause` in Apache Airflow v1 è in Apache Airflow v2`dags unpause`. Per ulteriori informazioni, consulta le [modifiche alla CLI di Airflow](http://airflow.apache.org/docs/apache-airflow/2.0.2/upgrading-to-2.html#airflow-cli-changes-in-2-0) nella versione 2.0.

## Comandi CLI supportati
<a name="airflow-cli-commands"></a>

La sezione seguente elenca i comandi CLI di Apache Airflow disponibili su Amazon MWAA.

### Comandi supportati
<a name="airflow-cli-commands-supported"></a>

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


| Versioni secondarie | Comando | 
| --- | --- | 
| v3.0.6 | [dettagli degli asset](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#details) | 
| v3.0.6 | [elenco delle risorse](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#list) | 
| v3.0.6 | [gli asset si materializzano](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#materialize) | 
| v3.0.6 | [backfill crea](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 | [connessioni aggiungi](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#add) | 
| v3.0.6 | [connessioni cancellate](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete) | 
| v3.0.6 | [giorni eliminati](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete_repeat1) | 
| v3.0.6 | [elenco dei giorni](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 | [giorni 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-run](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list-runs) | 
| v3.0.6 | [dags successiva esecuzione](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#next-execution) | 
| v3.0.6 | [giorni di pausa](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#pause) | 
| v3.0.6 | [rapporto dags](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#report) | 
| v3.0.6 | [i tag riserializzano](https://airflow.apache.org/docs/apache-airflow/2.4.3/cli-and-env-variables-ref.html#reserialize) | 
| v3.0.6 | [mostra giorni](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#show) | 
| v3.0.6 | [stato dei giorni](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#state) | 
| v3.0.6 | [giorni di test](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#test) | 
| v3.0.6 | [i giorni si innescano](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#trigger) | 
| v3.0.6 | [giorni in pausa](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#unpause) | 
| v3.0.6 | [db pulito](https://airflow.apache.org/docs/apache-airflow/2.4.3/cli-and-env-variables-ref.html#clean) | 
| v3.0.6 | [comportamenti dei fornitori](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#behaviours) | 
| v3.0.6 | [i fornitori ottengono](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#get_repeat2) | 
| v3.0.6 | [ganci per fornitori](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#hooks) | 
| v3.0.6 | [link ai fornitori](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#links) | 
| v3.0.6 | [elenco dei fornitori](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat4) | 
| v3.0.6 | [notifiche ai fornitori](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#notifications) | 
| v3.0.6 | [segreti dei fornitori](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#secrets) | 
| v3.0.6 | [trigger dei provider](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#triggerer) | 
| v3.0.6 | [widget dei fornitori](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#widgets) | 
| v3.0.6 | [ruoli aggiuntivi](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#add-perms) | 
| v3.0.6 | [ruoli del-perms](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#del-perms) | 
| v3.0.6 | [i ruoli creano](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#create) | 
| v3.0.6 | [elenco dei ruoli](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat5) | 
| v3.0.6 | [attività chiare](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#clear) | 
| v3.0.6 | [attività fallite - deps](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#failed-deps) | 
| v3.0.6 | [elenco delle attività](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat6) | 
| v3.0.6 | [renderizzazione delle attività](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#render) | 
| v3.0.6 | [stato delle attività](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#state_repeat1) | 
| v3.0.6 | [compiti 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 | [test delle attività](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#test_repeat1) | 
| v3.0.6 | [le variabili eliminano](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete_repeat4) | 
| v3.0.6 | [le variabili ottengono](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#get_repeat3) | 
| v3.0.6 | [set di variabili](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#set_repeat1) | 
| v3.0.6 | [elenco delle variabili](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat8) | 
| v3.0.6 | [versione](http://airflow.apache.org/docs/apache-airflow/1.10.12/cli-ref.html#version) | 

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


| Versioni secondarie | Comando | 
| --- | --- | 
| v2.0 \+ | [cheatsheet](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#cheat-sheet) | 
| v2.0 \+ | [connessioni aggiungi](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#add) | 
| v2.0 \+ | [eliminazione delle connessioni](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete) | 
| [v2.2\+ (nota)](#parsing-support) | [4 giorni di riempimento](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#backfill) | 
| v2.0 \+ | [giorni eliminati](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete_repeat1) | 
| [v2.2\+ (nota)](#parsing-support) | [elenco dei giorni](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 \+ | [giorni 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-run](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list-runs) | 
| [v2.2\+ (nota)](#parsing-support) | [dags successiva esecuzione](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#next-execution) | 
| v2.0 \+ | [giorni di pausa](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#pause) | 
| v2.0 \+ | [rapporto dags](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#report) | 
| v2.4 e versioni successive | [i dag riserializzano](https://airflow.apache.org/docs/apache-airflow/2.4.3/cli-and-env-variables-ref.html#reserialize) | 
| v2.0 \+ | [mostra giorni](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#show) | 
| v2.0 \+ | [stato dei giorni](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#state) | 
| v2.0 \+ | [giorni di test](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#test) | 
| v2.0 \+ | [i giorni si innescano](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#trigger) | 
| v2.0 \+ | [giorni in pausa](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#unpause) | 
| v2.4 e versioni successive | [db pulito](https://airflow.apache.org/docs/apache-airflow/2.4.3/cli-and-env-variables-ref.html#clean) | 
| v2.0 \+ | [comportamenti dei fornitori](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#behaviours) | 
| v2.0 \+ | [i fornitori ottengono](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#get_repeat2) | 
| v2.0 \+ | [ganci per fornitori](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#hooks) | 
| v2.0 \+ | [link ai fornitori](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#links) | 
| v2.0 \+ | [elenco dei fornitori](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat4) | 
| v2.8 \+ | [notifiche ai fornitori](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#notifications) | 
| v2.6 \+ | [segreti dei fornitori](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#secrets) | 
| v2.7 \+ | [trigger dei provider](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#triggerer) | 
| v2.0 \+ | [widget dei fornitori](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#widgets) | 
| v2.6 \+ | [ruoli add-perms](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#add-perms) | 
| v2.6 \+ | [ruoli del-perms](https://airflow.apache.org/docs/apache-airflow/stable/cli-and-env-variables-ref.html#del-perms) | 
| v2.6 \+ | [i ruoli creano](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#create) | 
| v2.0 \+ | [elenco dei ruoli](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat5) | 
| v2.0 \+ | [compiti chiari](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#clear) | 
| v2.0 \+ | [attività fallite - deps](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#failed-deps) | 
| v2.0 \+ | [elenco delle attività](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat6) | 
| v2.0 \+ | [renderizzazione delle attività](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#render) | 
| v2.0 \+ | [attività eseguite](https://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#run) | 
| v2.0 \+ | [stato delle attività](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#state_repeat1) | 
| v2.0 \+ | [attività 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 \+ | [test delle attività](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#test_repeat1) | 
| v2.0 \+ | [le variabili si eliminano](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#delete_repeat4) | 
| v2.0 \+ | [le variabili ottengono](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#get_repeat3) | 
| v2.0 \+ | [set di variabili](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#set_repeat1) | 
| v2.0 \+ | [elenco delle variabili](http://airflow.apache.org/docs/apache-airflow/2.2.2/cli-and-env-variables-ref.html#list_repeat8) | 
| v2.0 \+ | [versione](http://airflow.apache.org/docs/apache-airflow/1.10.12/cli-ref.html#version) | 

------

### Utilizzo di comandi che analizzano DAGs
<a name="parsing-support"></a>

Se nel tuo ambiente è in esecuzione Apache Airflow v2.0.2, i comandi CLI che DAGs analizzano falliranno se il DAG utilizza plugin che dipendono dai pacchetti installati tramite: `requirements.txt`

**Apache Airflow versione 2.0.2**
+ `dags backfill`
+ `dags list`
+ `dags list-runs`
+ `dags next-execution`

È possibile utilizzare questi comandi CLI se DAGs non si utilizzano plug-in che dipendono dai pacchetti installati tramite un. `requirements.txt`

## Codice di esempio
<a name="airflow-cli-command-examples"></a>

La sezione seguente contiene esempi di diversi modi di utilizzare l'Apache Airflow CLI.

### Imposta, ottieni o elimina una variabile Apache Airflow v2
<a name="example-airflow-cli-commands-bash"></a>

È possibile utilizzare il seguente codice di esempio per impostare, ottenere o eliminare una variabile nel formato di. `<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
```

### Aggiungere una configurazione quando si attiva un DAG
<a name="example-airflow-cli-commands-trigger"></a>

È possibile utilizzare il seguente codice di esempio con Apache Airflow v2 per aggiungere una configurazione quando si attiva un DAG, ad esempio. `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)
```

### Esegui i comandi CLI su un tunnel SSH verso un host bastion
<a name="example-airflow-cli-commands-private"></a>

Usa l'esempio seguente per eseguire i comandi CLI Airflow utilizzando un proxy tunnel SSH verso un host Linux Bastion.

**Usare 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}}
   ```